ggplot2
is a R
package dedicated to data visualization. It can greatly improve the quality and aesthetics of your graphics, and will
make you much more efficient in creating them.ggplot2
allows to build almost any type of chart. The R graph
ggplot2
examples.ggplot2
tips that you can apply to any chart, like customizing a title, adding annotation, or using faceting.
ggplot2
, a
good starting point is probably this online course.
fill
and color
ggplot2
allows to customize the shape colors thanks to its fill
and color
arguments. It is important to understand the diffence between both. Note that `color` and `colour` always have the same effect.
library(ggplot2) ggplot(mtcars, aes(x=drat)) + geom_density( color="purple", fill="#69b3a2", size=2 )
ggplot2
ggplot2
allows to automatically assign a marker color to a variable. Basically, you just have to specify the variable in the aes()
part of the call. Moreover, a legend comes for free.
library(ggplot2) ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(size=6)
ggplot2
ggplot2
provides a color scale by default. Several methods are available to change it:
→ Included in ggplot2
→ R Color Brewer
→ Viridis
→ All other: Paletteer
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
ggplot2
natively supports several methods to customize the color palette:
All the existing color palettes are available in Paletteer
. Just specify the package and palette names to use!
All the existing color palettes are available in Paletteer
. Just specify the package and palette names to use!
All the existing color palettes are available in Paletteer
. Just specify the package and palette names to use!
All the existing color palettes are available in Paletteer
. Just specify the package and palette names to use!
All the existing color palettes are available in Paletteer
. Just specify the package and palette names to use!
p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(size=6)
p + scale_color_hue(h = c(180, 300))
p + scale_color_manual(values=c("#69b3a2", "purple", "black"))
p + scale_color_grey()
p + scale_color_brewer(palette = "BuPu")
p + scale_color_brewer(palette = "RdYlBu")
p + scale_color_brewer(palette = "Paired")
p + scale_color_brewer(palette = "PuOr")
p + scale_color_brewer(palette = "Spectral")
p + scale_color_brewer(palette = "Pastel1")
p + scale_color_viridis(discrete=TRUE, option="magma")
p + scale_color_viridis(discrete=TRUE, option="inferno")
p + scale_color_viridis(discrete=TRUE, option="plasma")
p + scale_color_viridis(discrete=TRUE, option="viridis")
p + scale_color_viridis(discrete=TRUE, option="cividis")
p + scale_color_paletteer_d(nord, aurora)
p + scale_color_paletteer_d(awtools, a_palette)
p + scale_color_paletteer_d(dutchmasters, milkmaid)
scale_color_paletteer_d(ggsci, nrc_npg)
p + scale_color_paletteer_d(ggthemes, calc)
p + scale_color_hue(h = c(180, 300))See all See all See all See all See all See all See all See all See all See all See all
I few stuff I often need to remember:
library(paletteer) ; paletteer_c(package = "scico", palette = "berlin", n = 10)