Scientific plots using ggplot2 in R
Below you can find the R code to create a publication-ready plot. You can change the details of the theme() functions to tail the plot to your needs.
# Loading required libraries
library(ggplot2)
library(grid)
# Load the function
theme_science1 <- function(base_size = 18,
facet_border_col = "white",
legend_justification = c(0,1),
legend_position = c(0,1)){
theme_bw(base_size = base_size) +
theme(axis.line = element_line(size = 0.7, color = 'black'),
panel.border = element_blank(),
panel.grid.major = element_line(size = 0.1, color = "grey90", linetype = "dotted"),
axis.title.x = element_text(face="bold", colour="black", size = base_size*1.5, vjust = -0.3),
axis.text.x = element_text(face="plain", colour="black", size = base_size),
axis.title.y = element_text(face="bold", colour="black", size = base_size*1.5, , vjust = 1.5),
axis.text.y = element_text(face="plain", colour="black", size = base_size),
plot.title = element_text(face="bold", size = base_size*2),
legend.title = element_text(size = base_size*1.5),
legend.text = element_text(face="plain", size = base_size),
legend.key.height= grid::unit(2,"line"),
legend.key = element_blank(),
legend.background = element_rect(colour = "black", fill = "white"),
strip.background = element_rect(fill = 'white', colour = "white"),
strip.text.x = element_text(size = base_size*1.5),
strip.text.y = element_text(size = base_size*1.5),
panel.background = element_rect(colour = facet_border_col, size = 0.7),
legend.justification = legend_justification,
legend.position=legend_position)
}
# Data and plot
data(airquality)
gp <- ggplot(airquality, aes(x=Wind,y=Ozone)) +
geom_point(shape=16,size=3) +
geom_smooth(method="lm") +
theme_science1()
# Loading required libraries
library(ggplot2)
library(grid)
# Load the function
theme_science1 <- function(base_size = 18,
facet_border_col = "white",
legend_justification = c(0,1),
legend_position = c(0,1)){
theme_bw(base_size = base_size) +
theme(axis.line = element_line(size = 0.7, color = 'black'),
panel.border = element_blank(),
panel.grid.major = element_line(size = 0.1, color = "grey90", linetype = "dotted"),
axis.title.x = element_text(face="bold", colour="black", size = base_size*1.5, vjust = -0.3),
axis.text.x = element_text(face="plain", colour="black", size = base_size),
axis.title.y = element_text(face="bold", colour="black", size = base_size*1.5, , vjust = 1.5),
axis.text.y = element_text(face="plain", colour="black", size = base_size),
plot.title = element_text(face="bold", size = base_size*2),
legend.title = element_text(size = base_size*1.5),
legend.text = element_text(face="plain", size = base_size),
legend.key.height= grid::unit(2,"line"),
legend.key = element_blank(),
legend.background = element_rect(colour = "black", fill = "white"),
strip.background = element_rect(fill = 'white', colour = "white"),
strip.text.x = element_text(size = base_size*1.5),
strip.text.y = element_text(size = base_size*1.5),
panel.background = element_rect(colour = facet_border_col, size = 0.7),
legend.justification = legend_justification,
legend.position=legend_position)
}
# Data and plot
data(airquality)
gp <- ggplot(airquality, aes(x=Wind,y=Ozone)) +
geom_point(shape=16,size=3) +
geom_smooth(method="lm") +
theme_science1()
Here it is an example:
Comments
Post a Comment