AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
My experience so far with R is when I can't do something as simple as this, I'm missing a very fundamental concept. It goes without saying that it requires ggplot2 to work. But I'd like the color scale even finer, and in a perfect world, force a Z of zero to be the white color. These functions provide the option to use continuous palettes along with the ggplot2 package. But if I put in a number greater than 16, that's all I get, 16 colored segments, evenly changing from red, to white, to blue. This suggests making this number larger causes a finer graduation of colors. How to set fixed continuous colour values in ggplot2 Ask Question Asked 9 years, 4 months ago Modified 4 years, 6 months ago Viewed 76k times Part of R Language Collective 29 Im plotting a lot of graphics and Id like for all of them to have the same colour scale so I can compare one to another. The following R programming syntax explains how to. Changing the 3 to a 7 causes more shades of red and blue creating 2 repeat color range segments with two reddish colors left over as the color range tries to recycle. Example: Set New Continuous Color Range in ggplot2 Plot Using colorRampPalette() & scalecolourgradientn(). When I plot my dataframe with the "50" in the last code line as 3, I get the predictable R recycle behavior of the red, white, and blue colors repeating five times with the 16th color bar segment white. One data point looks like: 1302525 225167 -3.5 The color palette should be chosen depending on type of the variable, with sequential or diverging color palettes being used for continuous variables and. Sample data These two data sets will be used to generate the graphs below. A good general-purpose solution is to just use the colorblind-friendly palette below. They are also not friendly for colorblind viewers. If you have many data points, or if your data scales are discrete, then the data points might overlap and it will be impossible to see if there are many points at the same location. Solution The default colors in ggplot2 can be difficult to distinguish from one another because they have equal luminance. Levelplot(Z~X*Y, df, panel=, cex=0.2,Ĭol.regions=colorRampPalette(c("red","white","blue"))(50)) See Colors (ggplot2) and Shapes and line types for more information about colors and shapes. I've tried base R, ggplot2, and latticeExtra, and as best I can, I can come up with the following which does almost what I want: library(lattice)ĭf = read.table(file"whatever", header=T) I am not interested in smoothing I want the point Z values to plot according to a smoothly varying color palette much like Gnuplot can do with the proper smooth color palette. I am trying to plot a fairly regular distribution of several thousand (X,Y) points each associated with a value, let's call Z, which varies very irregularly between, say, -20 to +20.
0 Comments
Read More
Leave a Reply. |