Skip to content

@cdesante /ggd4g1.r
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Color4
#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.