Hey I want to create my own custom palette of color in R using the brewer.pal() function. And then I want to view it using the image function.
ny<-brewer.pal(7,"Blues")
image(x=1:7,y=1,z=as.matrix(1:7),col=ny)
This code gives 7 shdes of blue, however i want to give my own choice of 7 different colors.
image(x=1:7,y=1,z=as.matrix(1:7),col=c("Reds","Blues"))
I thought of trying this function, but its obvious wrong. Can someone please help me. I specifically want to use the brewer.pal() and image() funcions
If you'd prefer a gradient between 2+ colors of your choosing, you could also use colorRampPalette
pretty = colorRampPalette(c('#EF6780', '#80ef67', '#6780ef'))
image(x=1:7,y=1,z=as.matrix(1:7),col=pretty(200))
You can specify colors as hexadecimal colors in R. For example
image(x=1:7,y=1,z=as.matrix(1:7),col= "#CC6666")
References:
http://www.color-hex.com/
http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
Related
I have trouble for plotting my raster and some points as sf object over that. I use aes(color=...) to assign color to different types of my points. But I want to change the colours to specific ones like red and blue and yellow. also I can't use scale_fill_manual because my raster layer's colours which is in first layer, shouldn't be changed. Is there any solution for this problem?
thanks in advance
geom_raster(data=dem2,aes(x=x,y=y,fill=elevation))+
geom_sf(data=mypoint,aes(shape=Type,colour=ranges))
The fill parameter inside aes wich you can manipulate manually using scale_fill_manual works perfectly with polygons or raster data. But, when you need to color points
or simple lines, the color parameter inside aes is prefered. Said that, if you want to assing different colors to your points, use scale_color_manual, this shouldnt interfer in your raster color.
package "ggnewscale" will work in this problem. It allows to use different scale for color in one plot.
I have the following two colours:
$light-green: #99E2D0;
$dark-green: #008766;
I'm sure I can get the dark green from the lighter green by using a SASS function (I noticed they have the same hue). I have tried many combinations using lighten(), darken(), saturate(), etc... but have not succeeded. I ask the following question: is there a way to find out which function associates two specific colours? Do you know which function I have to use to get that colour? Thank you in advance
You can use online tool to find that for you such as Sass Colour Function Calculator.
In your example:
$light-green: #99E2D0;
$dark-green: darken(saturate($light-green, 44.27), 47.84);
Can someone let me know the various colors which produced the excellent color mix in the 4-panel plot on this link:?
http://www.enr.gov.nt.ca/state-environment/13-projected-trends-temperature-and-precipitation-arctic
I need the color ramp on the right of the plot for precipitation.
I tried something like:
col=colorRampPalette(c( "red3","orange","gold1", "yellow", "lightskyblue","steelblue3", "royalblue3",
"darkblue","darkblue"))(30))
but could not get it right. A list of colors in R is found here:
http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf
Many thanks.
AZ.
You can identify the colors using the Eyedropper Tool in Firefox, although it's a bit tedious. As you can see below, the actual palette is close but not quite the same as the Color Brewer palette.
actual <- c('#2F2C62', '#42399B', '#4A52A7', '#59AFEA', '#7BCEB8', '#A7DA64',
'#EFF121', '#F5952D', '#E93131', '#D70131', '#D70131')
library(colorRamps)
barplot(cbind(1:11,1:11),beside=TRUE,names=c("actual","brewer.pal(11,'RdYlBu')"),
col=c(rev(actual),brewer.pal(11,"RdYlBu")))
It looks very close to the color scheme called 'RdYlBl' from RColorBrewer.
Here is how it looks like:
require('RColorBrewer')
display.brewer.pal(11,'RdYlBu')
(to use it: brewer.pal(11,'RdYlBu'))
I am using R to create a plot that contains 20 distinct groups, and I would like to color each of them differently. I am also familiar with Matlab and when working with that program I have found that "distinguishable_colors" matlab file worked best for distinguishing different colors 1. I have looked at the "rainbow", "rainbow_hcl", and "brewer" palettes, but none of them look as good as "distinguishable_colors.mat". I am wondering if anyone knows of a function in R that will create the same palette as the "distinguishable_colors.mat" matlab function?
That function in MatLab seems to iteratively search over RBG space for sets of color which are maximally different from each other. I don't know of such a thing in R, but we can come pretty close.
We can find a color palette of a few colors which suits our needs (perhaps using http://colorbrewer2.org/) and use those seed color to create a colorRampPalette for any number of colors.
pal<-colorRampPalette(c('#e41a1c','#377eb8','#4daf4a','#984ea3','#ff7f00'))
N=10
plot(rnorm(N),rnorm(N),pch=16,col=pal(N),cex=3)
The R package Polychrome provides tools for qualitative palettes with many (20 or more) colors. It comes with two vignettes giving the provided palettes and tools for creating palettes.
Is it possible to have different colours in my plot in Scilab? I use the mtlb_hold to hold the graph and it works fine, but my problem is that then I have the same colours in my graph. In Matlab with the hold command, I have different colours. Is it possible to have different colours in Scilab too?
Thank you in advance.
Just found it. In the plot function, for example plot(), you can pass a second argument which specifies the color that will be used. For example, you can use use b for blue color, g for green, r for red and call plot() like this: plot(z,"r").
The SciLab documentation provides examples for using colors:
https://help.scilab.org/doc/5.3.3/en_US/color.html
The plot2d()-function e.g. accepts an attribute style, where you can even specify a color for each function with its full name:
plot2d(x,[sin(x),cos(x)],style=[color("red"),color("green")]);