Overplotting with various color palettes in ggplot2

Dear Readers,

I have a data set for which I have raw data and for which I additionally compute some kind of smoothing function. Then I want to display the raw data as dots and anti-aliasing as a row. This works with the following:

Loc <- seq(from=1,to=50) Loc <- append(Loc,Loc) x <- seq(from=0,to=45,by=0.01) Val <- sample(x,100) labels <- NULL labels[1:50] <- 'one' labels[51:100] <- 'two' x2 <- seq(from=12,to=32,by=0.01) Val2 <- sample(x2,100) raw <- data.frame(loc=Loc,value=Val,lab=labels) smooth <- data.frame(loc=Loc,value=Val2,lab=labels) pl <- ggplot(raw,aes(loc,value,colour=lab)) + geom_point() + geom_line(data=smooth) print(pl) 

The result is as follows:

enter image description here

The problem is that my actual data contains so many data points that using the same color palette will be very confusing (the difference between the point and the line will be almost indistinguishable). Preferably, I would make geom_lines () a little darker. I tried with scale_colour_hue(l=40) , but this leads to the fact that geom_points () will also be darker.

Thanks for any suggestions!

0
r ggplot2
source share
2 answers

I don't have the perfect answer for you, but I have one that works. You can individually control the colors of your lines, breaking them into separate geometries, for example:

 ggplot(raw,aes(loc,value)) + geom_point(aes(col=lab)) + geom_line(data=smooth[smooth$lab=="one",], colour="blue", size=1) + geom_line(data=smooth[smooth$lab=="two",], colour="black", size=1) 

chart 1

The disadvantage of this is that you need to manually specify the row selection, but the advantage is that you can manually specify the visual properties of each row.

Another option is to use the same palette, but make the lines larger and partially transparent, for example:

 ggplot(raw,aes(loc,value,colour=lab)) + geom_point() + geom_line(data=smooth, size=2, alpha=0.5) 

chart 2

You should be able to customize things from here to suit your needs.

+2
source share

Instead of geom_point() lines, you can try to make the points brighter by setting the alpha= value in geom_point() .

 pl <- ggplot(raw,aes(loc,value,colour=lab)) + geom_point(alpha=0.5) + geom_line(data=smooth) print(pl) 

enter image description here

+1
source share

All Articles