Is it possible to plot two sets of data on the same plot, but use different color palettes for each set?
testdf <- data.frame( x = rnorm(100),
y1 = rnorm(100, mean = 0, sd = 1),
y2 = rnorm(100, mean = 10, sd = 1),
yc = rnorm(100, mean = 0, sd = 3))
ggplot(testdf, aes(x, y1, colour = yc)) + geom_point() +
geom_point(aes(y = y2))
What I would like to see is one set of data, say y1
, in blues (color set by yc
), and the other set in reds (again color set by yc
).
The legend should then show 2 color scales, one in blue, the other red.
Thanks for your suggestions.
A color can be specified either by name (e.g.: “red”) or by hexadecimal code (e.g. : “#FF1234”).
You simply pick up a single colour and combine it with either various amounts of white or various amounts of black to create different tones and shades that stand out from each other. You can mix as much black or white to get the contrast that you want.
In R, colors can be specified either by name (e.g col = “red”) or as a hexadecimal RGB triplet (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the RColorBrewer package.
To get your own palette up and running, you just need to swap in your own palette name where it says name = c(“insert your palette name here”), put that same palette name in place of 'your.palette.name'. Make sure you have named your red, green, and blue vectors r, g, b, respectively, and then you should be good to go.
If you translate the "blues" and "reds" to varying transparency, then it is not against ggplot's philosophy. So, using Thierry's Molten
version of the data set:
ggplot(Molten, aes(x, value, colour = variable, alpha = yc)) + geom_point()
Should do the trick.
That's not possible with ggplot2. I think it against the philosophy of ggplot2 because it complicates the interpreatation of the plot.
Another option is to use different shapes to separate the points.
testdf <- data.frame( x = rnorm(100),
y1 = rnorm(100, mean = 0, sd = 1),
y2 = rnorm(100, mean = 10, sd = 1),
yc = rnorm(100, mean = 0, sd = 3))
Molten <- melt(testdf, id.vars = c("x", "yc"))
ggplot(Molten, aes(x, value, colour = yc, shape = variable)) + geom_point()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With