![]() Plot.margin = unit(c(1, 1, 0.5, 0.5), "lines"), complete = TRUE)įor simple applications working with colors is straightforward in ggplot2 but when you have more advanced needs it can be a challenge. Plot.title = element_text(size = rel(1.2)), Plot.background = element_rect(colour = "white"), Strip.background = element_rect(fill = "grey80", colour = NA), Panel.background = element_rect(fill = "grey90", colour = NA), ![]() Legend.title = element_text(size = rel(0.8), face = "bold", hjust = 0), Legend.text = element_text(size = rel(0.8)), Legend.key = element_rect(fill = "grey95", colour = "white"), Legend.background = element_rect(colour = NA), Strip.text = element_text(size = rel(0.8)),Īxis.ticks = element_line(colour = "grey50"), Text = element_text(family = base_family, face = "plain", colour = "black", size = base_size, hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9),Īxis.text = element_text(size = rel(0.8), colour = "grey50"), Rect = element_rect(fill = "white", colour = "black", size = 0.5, linetype = 1), Line = element_line(colour = "black", size = 0.5, linetype = 1, lineend = "butt"), theme_grayįunction (base_size = 12, base_family = "") Note that the rel() function change the sizes relative to the base_size. If you wanted to create your own custom theme, you could extract the code directly from the gray theme and modify. If you want to change the theme for an entire session you can use theme_set as in theme_set(theme_bw()). # 3659 chic 127 17.0 5.75 9.365 14.941 3659 winter 1997Ī default plot in ggplot2 g<-ggplot(nmmaps, aes(date, temp))+geom_point(color="firebrick")īack to table of contents Tip on creating a custom theme # city date death temp dewpoint pm10 o3 time season year You can also download the data we’re using in this post here. For more detail on this dataset, consult Roger Peng’s book Statistical Methods in Environmental Epidemiology with R. To make the plots manageable we’re limiting the data to Chicago and 1997-2000. We’re using data from the National Morbidity and Mortality Air Pollution Study (NMMAPS). Create interactive, online versions of your plots (easier than you think).Adding a linear fit ( stat_smooth(method="lm")).Specifying the formula ( stat_smooth(formula=)).Default – adding LOESS or GAM ( stat_smooth()).Create a tiled correlation plot ( geom_tile()).Alternatives to the box plot ( geom_jitter() and geom_violin()).Flip a plot on it’s side ( coord_flip()).Add text annotation in the top-right, top-left etc. ![]() Color choice with continuous variables ( scale_color_gradient(), scale_color_gradient2()).Categorical variables: try a built-in palette (based on ) ( scale_color_brewer):.Categorical variables: manually select the colors ( scale_color_manual). ![]() Change the size of all plot text elements ( theme_set(), base_size).Put two (potentially unrelated) plots side by side ( pushViewport(), grid.arrange()).Create a grid of plots using two variables ( facet_grid()).Create a matrix of plots based on one variable ( facet_wrap()).Create a single row of plots based on one variable ( facet_wrap()).Changing the plot margin ( plot.margin).Change the plot background (not the panel) color ( plot.background).Change the panel color ( panel.background).Manually adding legend items ( guides(), override.aes).Leave a layer off the legend ( show_guide).Change the size of the symbols in the legend only ( guides(), guide_legend). ![]()
0 Comments
Leave a Reply. |