public
Created

Color4

  • Download Gist
ggd4g1.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#Load ggplot default data: Diamonds
library(ggplot2)
library(gridExtra)
data(diamonds)
head(diamonds)
diamonds <- diamonds[diamonds$color < "J",]
#http://127.0.0.1:25615/library/ggplot2/html/diamonds.html
 
#Random Colors
my.colors <- sample(colors(), 7)
RANDOM <- ggplot(data = diamonds) + geom_point(aes( x = carat, y = price, color=factor(color))
) + facet_wrap(~color) + scale_color_manual(values = my.colors) + labs(title = "+ scale_color_manual(values=sample(colors(), 7)\n" )
 
 
 
#Custom Colors 1
colors()
custom.colors.1 <- c("red", "orange" , "yellow", "green", "blue", "blueviolet", "violet")
C1 <- ggplot(data = diamonds) + geom_point(aes( x = carat, y = price, color=factor(color))
) + facet_wrap(~color) + scale_color_manual(values = custom.colors.1) + labs(title = "+ scale_color_manual(values=custom.colors.1)\n" )
 
 
#Custom Colors 2
custom.colors.2 <- c("skyblue1", "skyblue2" , "skyblue3", "steelblue", "springgreen2", "springgreen3", "springgreen4")
C2 <- ggplot(data = diamonds) + geom_point(aes( x = carat, y = price, color=factor(color))
) + facet_wrap(~color) + scale_color_manual(values = custom.colors.2
) + labs(title = " + scale_color_manual(values = custom.colors.2) \n" )
 
#Rainbow Colors
rainbow(6)
ROYGBIV <- rainbow(6)
RAINBOW <- ggplot(data = diamonds) + geom_point(aes( x = carat, y = price, color=factor(color))
) + facet_wrap(~color) + scale_color_manual(values = ROYGBIV) + labs(title = " + scale_color_manual(values = rainbow(6)) \n" )
 
 
Example.1 <- grid.arrange(RANDOM, C1, C2, RAINBOW, ncol=2)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.