ggplot box plot with data points: how to control legend appearance? - r

I tried various options, but I cannot find a way to achieve custom legend appearance (unless I export the figure to power point and edit it there...). I would like the legend to look like in the image below and wonder if that is at all possible:
I do not wish to make any changes in the figure itself:
Here is my sample data and code:
df = data.frame(sex = c(1,1,1,1,1, 2,2,2,2,2),
age_cat = c(1,1,1, 2,2,2, 1,1,1, 2),
score_type = c(1,2, 1,2, 1,2, 1,2, 1,2),
score = c(25,28,18,20,30, 37,40,35,43,45))
df$sex <- factor((df$sex))
df$age_cat <- factor((df$age_cat))
df$score_type <- factor((df$score_type))
windows(width=7, height=7)
library(ggplot2)
df %>%
ggplot( aes(x=score_type, y=score)) +
geom_boxplot(aes(color=sex),outlier.shape = NA, size=1.5, show.legend=T) +
geom_point(aes(color=sex, shape = age_cat, group = sex),
position=position_jitterdodge(dodge.width=0.9), size=3, show.legend=F) +
scale_color_manual(values=c("#0072B2", "#CC79A7"), name="",
labels=c("Male", "Female")) +
scale_shape_manual(name="", labels=c('Younger', 'Older'),
values=c(16, 17)) +
theme_bw()+
theme(panel.border = element_blank(), axis.ticks = element_blank(),
legend.position=c(0.9, 0.65), legend.text=element_text(size=11),
legend.title=element_text(size=11.5),
panel.grid.major.x = element_blank() ,
plot.title = element_text(size=11, face = "bold"),
axis.title=element_text(size=13),
axis.text.y = element_text(size=11),
axis.text.x = element_text(size=11),
plot.margin = unit(c(0.5,0.2,0,0.2), "cm")) +
labs(title= "", x = "",y = "Score") +
scale_y_continuous(breaks=c(0, 20, 40, 60, 80, 100),
labels=c('0', '20', '40', '60', '80', '100')) +
expand_limits(x=5, y=70) +
scale_x_discrete(labels = c("A", "B")) +
coord_cartesian(clip = "off")

You could achieve your desired result by
dropping show.legend=FALSE from geom_point
Overriding the shapes to be displayed in the legend using guides(shape = guide_legend(override.aes = list(shape = c(1, 2))))
library(ggplot2)
ggplot(df, aes(x = score_type, y = score)) +
geom_boxplot(aes(color = sex), outlier.shape = NA, size = 1.5) +
geom_point(aes(color = sex, shape = age_cat, group = sex),
position = position_jitterdodge(dodge.width = 0.9), size = 3
) +
scale_color_manual(
values = c("#0072B2", "#CC79A7"), name = "",
labels = c("Male", "Female")
) +
scale_shape_manual(
name = "", labels = c("Younger", "Older"),
values = c(16, 17)
) +
theme_bw() +
theme(
panel.border = element_blank(), axis.ticks = element_blank(),
legend.position = c(0.9, 0.65), legend.text = element_text(size = 11),
legend.title = element_text(size = 11.5),
panel.grid.major.x = element_blank(),
plot.title = element_text(size = 11, face = "bold"),
axis.title = element_text(size = 13),
axis.text.y = element_text(size = 11),
axis.text.x = element_text(size = 11),
plot.margin = unit(c(0.5, 0.2, 0, 0.2), "cm")
) +
labs(title = "", x = "", y = "Score") +
scale_y_continuous(
breaks = c(0, 20, 40, 60, 80, 100),
labels = c("0", "20", "40", "60", "80", "100")
) +
expand_limits(x = 5, y = 70) +
scale_x_discrete(labels = c("A", "B")) +
coord_cartesian(clip = "off") +
guides(shape = guide_legend(override.aes = list(shape = c(1, 2))))

Related

In ggplot2, how can I use multi-row x-axis labels with facet_wraps?

I have multi-row x-axis labels such that the first row is month and the second row is year. However, I run into check_aesthetics() errors when I try to use the multi-row axis labels with facet_wrap().
Example Data:
library(data.table)
library(dplyr)
library(ggplot2)
df1 <- data.frame(matrix(ncol = 3, nrow = 12))
colnames(df1)[1:3] <- c("Date", "Group", "Value")
df1$Date <- rep(seq.Date(as.Date("2020-03-14"),as.Date("2020-08-20"),"1 month"),2)
df1$Group <- sort(rep(c("A","B"),6))
df1$Value <- rnorm(12,50,10)
df1 <- df1 %>%
mutate(Month = month(Date),
Year = year(Date),
date = zoo::as.yearmon(paste(Year, Month), "%Y %m"))
df2 <- data.frame(matrix(ncol = 3, nrow = 12))
colnames(df2)[1:3] <- c("Date", "Group", "Value")
df2$Date <- rep(seq.Date(as.Date("2021-03-14"),as.Date("2021-08-20"),"1 month"),2)
df2$Group <- sort(rep(c("A","B"),6))
df2$Value <- rnorm(12,50,10)
df2 <- df2 %>%
mutate(Month = month(Date),
Year = year(Date),
date = zoo::as.yearmon(paste(Year, Month), "%Y %m"))
df3 <- rbind(df1,df2)
cols <- c("A" = "#ca0020", "B" = "#0571b0")
Figure without facet_wrap() showing the multi-row x-axis
ggplot(data = df3, aes(x = factor(date), y = Value, color = Group, group = paste(Year,Group))) +
geom_line() +
geom_point(size = 3, aes(fill = Group), color = "black", shape = 21) +
scale_fill_manual(values = cols) +
scale_color_manual(values = cols) +
scale_x_discrete(labels=substr(df3$date,1,3))+
labs(x = "") +
theme_bw() +
theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
panel.grid = element_blank(),
text = element_text(size = 16),
axis.text.x = element_text(size = 14, color = "black", angle = 90, vjust = 0.5, hjust = 1),
axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_blank(),
legend.direction = "horizontal",
legend.margin = margin(),
legend.background = element_blank(),
legend.position = c(0.1,0.93),
panel.border = element_blank()) +
guides(fill = guide_legend(nrow = 2)) +
coord_cartesian(clip = 'off', ylim = c(0, 100)) +
annotation_custom(grid::rectGrob(gp = grid::gpar(fill = NA))) +
annotate(geom = "text", x = c(3.5,9.5), y = -15, label = unique(df3$Year), size = 6) +
annotate('rect',
xmin = 6.35,
xmax = 6.65,
ymin = -10, ymax = 0, fill = 'white') +
annotate('segment',
x = c(6.35, 6.65),
xend = c(6.35, 6.65), y = -10, yend = 0)
Now when I try to add the facet_wrap()...
ggplot(data = df3, aes(x = factor(date), y = Value, color = Group, group = paste(Year,Group))) +
geom_line() +
geom_point(size = 3, aes(fill = Group), color = "black", shape = 21) +
scale_fill_manual(values = cols) +
scale_color_manual(values = cols) +
scale_x_discrete(labels=substr(df3$date,1,3))+
labs(x = "") +
theme_bw() +
theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
panel.grid = element_blank(),
text = element_text(size = 16),
axis.text.x = element_text(size = 14, color = "black", angle = 90, vjust = 0.5, hjust = 1),
axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_blank(),
legend.direction = "horizontal",
legend.margin = margin(),
legend.background = element_blank(),
legend.position = c(0.1,0.93),
panel.border = element_blank()) +
guides(fill = guide_legend(nrow = 2)) +
coord_cartesian(clip = 'off', ylim = c(0, 100)) +
annotation_custom(grid::rectGrob(gp = grid::gpar(fill = NA))) +
annotate(geom = "text", x = c(3.5,9.5), y = -15, label = unique(df3$Year), size = 6) +
annotate('rect',
xmin = 6.35,
xmax = 6.65,
ymin = -10, ymax = 0, fill = 'white') +
annotate('segment',
x = c(6.35, 6.65),
xend = c(6.35, 6.65), y = -10, yend = 0) +
facet_wrap(~Group)
...it throws the error Error in `check_aesthetics()`: ! Aesthetics must be either length 1 or the same as the data (4): label.
The error resides within annotate(geom = "text", x = c(3.5,9.5), y = -15, label = unique(df3$Year), size = 6) + but I can't figure out how to fix it. I have tried changing the label = and the x = but no luck. The ideal figure would have two plots, each with multi-row x-axis labels where, similar to the example figure above, the top row is month and the second row is year. Any thoughts on how to achieve this?
If you don't mind moving the year value to the strip you could use ggh4x package.
library(dplyr)
library(ggplot2)
library(lubridate)
library(ggh4x)
ggplot(data = df3, aes(x = factor(date), y = Value, color = Group, group = paste(Year,Group))) +
geom_line() +
geom_point(size = 3, aes(fill = Group), color = "black", shape = 21) +
scale_fill_manual(values = cols) +
scale_color_manual(values = cols) +
scale_x_discrete(labels=substr(df3$date,1,3))+
labs(x = NULL) +
theme_bw() +
theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
panel.grid = element_blank(),
text = element_text(size = 16),
axis.text.x = element_text(size = 14, color = "black", angle = 90, vjust = 0.5, hjust = 1),
axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_blank(),
legend.direction = "horizontal",
legend.margin = margin(),
legend.background = element_blank(),
legend.position = c(0.1,0.90),
panel.border = element_blank()) +
guides(fill = guide_legend(nrow = 2)) +
coord_cartesian(clip = 'off', ylim = c(0, 100)) +
facet_nested(~Group + Year, scales = "free_x")
Created on 2022-10-12 with reprex v2.0.2
One kind of hacky way to do this is to just make two text annotations
ggplot(data = df3, aes(x = factor(date), y = Value, color = Group, group = paste(Year,Group))) +
geom_line() +
geom_point(size = 3, aes(fill = Group), color = "black", shape = 21) +
scale_fill_manual(values = cols) +
scale_color_manual(values = cols) +
scale_x_discrete(labels=substr(df3$date,1,3))+
labs(x = "") +
theme_bw() +
theme(plot.margin = unit(c(1, 1, 2, 1), "lines"),
panel.grid = element_blank(),
text = element_text(size = 16),
axis.text.x = element_text(size = 14, color = "black", angle = 90, vjust = 0.5, hjust = 1),
axis.text.y = element_text(size = 14, color = "black"),
legend.title = element_blank(),
legend.direction = "horizontal",
legend.margin = margin(),
legend.background = element_blank(),
legend.position = c(0.1,0.93),
panel.border = element_blank()) +
guides(fill = guide_legend(nrow = 2)) +
coord_cartesian(clip = 'off', ylim = c(0, 100)) +
annotation_custom(grid::rectGrob(gp = grid::gpar(fill = NA))) +
annotate(geom = "text", x = c(3.5), y = -15, label = 2020, size = 6) +
annotate(geom = "text", x = c(9.5), y = -15, label = 2021, size = 6) +
annotate('rect',
xmin = 6.35,
xmax = 6.65,
ymin = -10, ymax = 0, fill = 'white') +
annotate('segment',
x = c(6.35, 6.65),
xend = c(6.35, 6.65), y = -10, yend = 0) +
facet_wrap(~Group)

Barcharts: grouping bars using facet_wrap

I want to group these bars by the variable "env".
ggplot(dat, aes(x = Sample, fill = phylum, y = Abundance)) +
geom_bar(position="fill", stat = "identity") + theme_bw() +
facet_wrap( ~ env) +
theme(axis.text.x = element_text(angle = 90, size = 13, colour = "black", vjust = 0.5, hjust = 1), axis.title.x = element_text(size = 15),
axis.text.y = element_text(size = 13, vjust = 0.5, hjust = 1), axis.title.y = element_text(size = 15), legend.title = element_text(size = 15),
legend.text = element_text(size = 15, colour = "black")) +
ggtitle("Minion samples: Proteobacteria Phyla") + scale_y_continuous(labels = percent_format(), limits=c(0,1)) +
scale_fill_manual(values = c("Acidobacteria"="#3288bd",
"Actinobacteria" = "#99d594",
"Candidatus Rokubacteria" = "#74c476",
"Chloroflexi"= "#e6f598",
"Planctomycetes"="#fee08b",
"Proteobacteria" = "#fc8d59",
"Verrucomicrobia" = "#a50f15",
"Taxa less than 1%" = "#d53e4f"))
I get this:
I would like to have an unique x-axis and get rid of these empty spaces. Is there an other option beside facet_wrap?
Thanks
As per the comments, indeed using facet_wrap(~env, scales = "free, nrow =1) will solve your issue.
Moreover, you might want to have an equal width for the histograms, in this case you can use facet_grid and the space argument to have something like this:
ggplot(dat, aes(x = Sample, fill = phylum, y = Abundance)) +
geom_bar(position="fill", stat = "identity") + theme_bw() +
facet_grid(. ~ env, scales = "free", space = "free")+
theme(axis.text.x = element_text(angle = 90, size = 13, colour = "black", vjust = 0.5, hjust = 1), axis.title.x = element_text(size = 15),
axis.text.y = element_text(size = 13, vjust = 0.5, hjust = 1), axis.title.y = element_text(size = 15), legend.title = element_text(size = 15),
legend.text = element_text(size = 15, colour = "black")) +
ggtitle("Minion samples: Proteobacteria Phyla") + scale_y_continuous(labels = percent_format(), limits=c(0,1)) +
scale_fill_manual(values = c("Acidobacteria"="#3288bd",
"Actinobacteria" = "#99d594",
"Candidatus Rokubacteria" = "#74c476",
"Chloroflexi"= "#e6f598",
"Planctomycetes"="#fee08b",
"Proteobacteria" = "#fc8d59",
"Verrucomicrobia" = "#a50f15",
"Taxa less than 1%" = "#d53e4f"))
Whereas, facet_wrap(~ env, scales = "free", nrow = 1) results in unequal width distribution when free on one row:
ggplot(dat, aes(x = Sample, fill = phylum, y = Abundance)) +
geom_bar(position="fill", stat = "identity") + theme_bw() +
facet_wrap(~ env, scales = "free", nrow = 1)+
theme(axis.text.x = element_text(angle = 90, size = 13, colour = "black", vjust = 0.5, hjust = 1), axis.title.x = element_text(size = 15),
axis.text.y = element_text(size = 13, vjust = 0.5, hjust = 1), axis.title.y = element_text(size = 15), legend.title = element_text(size = 15),
legend.text = element_text(size = 15, colour = "black")) +
ggtitle("Minion samples: Proteobacteria Phyla") + scale_y_continuous(labels = percent_format(), limits=c(0,1)) +
scale_fill_manual(values = c("Acidobacteria"="#3288bd",
"Actinobacteria" = "#99d594",
"Candidatus Rokubacteria" = "#74c476",
"Chloroflexi"= "#e6f598",
"Planctomycetes"="#fee08b",
"Proteobacteria" = "#fc8d59",
"Verrucomicrobia" = "#a50f15",
"Taxa less than 1%" = "#d53e4f"))
Data
library(scales)
library(ggplot2)
set.seed(18)
dat = data.frame(
env = factor(rep(sample(c("Dry", "Fossil", "Wet", "Soil"), size = 25, prob = c(3,2,18,2), replace = T), each=8), levels =c("Dry", "Fossil", "Wet", "Soil")),
Sample = rep(paste0("Sample_",letters[1:25]), each=8),
phylum = rep(c("Acidobacteria", "Actinobacteria","Candidatus Rokubacteria","Chloroflexi","Planctomycetes", "Proteobacteria", "Verrucomicrobia","Taxa less than 1%"),times = 25),
Abundance = runif(200,0,1))

Adding asterisk to flag significance on ggplot

I have this bar graph, and want to show asterisks that flag significance (**).
viz_data_one <- tibble(
age_group = c(rep("Young Adult", 4), rep("Older Adult", 4)),
MemoryAccuracy = c(32.8, 28.448, 27.672, 27.075, 29.667, 28.944, 27.556, 28.889),
upper = MemoryAccuracy + 1.76,
lower = MemoryAccuracy - 1.76,
reward = rep(c("Self High Value", "Self Low Value", "Other High Value", "Other Low Value"), 2)
) %>%
mutate(
reward = as_factor(reward) %>% fct_relevel("Self High Value",
"Self Low Value",
"Other High Value",
"Other Low Value"))
viz_data_one <- viz_data_one %>%
mutate(upper = MemoryAccuracy + ifelse(age_group == "Young Adult", 1.76, 1.94),
lower = MemoryAccuracy - ifelse(age_group == "Young Adult", 1.76, 1.94))
p <- viz_data_one %>%
ggplot(aes(x = age_group,
y = MemoryAccuracy,
fill = reward,
ymin = lower,
ymax = upper)) +
geom_col(width = .5, position = position_dodge(.6),
color = "black", key_glyph = "polygon") +
geom_errorbar(width = .1, position = position_dodge(.6)) +
scale_fill_manual(values = c("#E495A5", "#ABB065", "#39BEB1", "#ACA4E2" )) +
labs(
x = "Age Group",
y = "Memory Accuracy (%)",
fill = NULL,
title = ""
) +
theme(
plot.margin = unit(c(1, 1, 1, 1), "cm"),
panel.background = element_blank(),
plot.title = element_text(size = 14, face = "bold",
hjust = 0.5,
margin = margin(b = 15)),
axis.line = element_line(color = "black"),
axis.title = element_text(size = 14, color = "black",
face = "bold"),
axis.text = element_text(size = 18, color = "black"),
axis.text.x = element_text(margin = margin(t = 10)),
axis.text.y = element_text(size = 14),
axis.title.y = element_text(margin = margin(r = 10)),
axis.ticks.x = element_blank(),
legend.position = c(0.90, 0.99),
legend.background = element_rect(color = "black"),
legend.text = element_text(size = 15),
legend.margin = margin(t = 5, l = 5, r = 5, b = 5),
legend.key = element_rect(color = NA, fill = NA)
) +
guides(
fill = guide_legend(
keywidth = .5,
keyheight = .5,
default.unit= "cm"
)
)
p + expand_limits(y = 40)
I want to add asterisk stars to the younger adult group (between self high value and self low value) and have everything else as ns. I've tried a few different things with ggpubr and geom_signif but had no luck.
I ended up solving this by drawing my own using geom_line
p +
geom_line(data=tibble(x=c(1.77,1.929), y=c(40,40)),
aes(x=x, y=y), inherit.aes = FALSE) +
geom_text(data=tibble(x=1.849, y = 41),
aes(x=x, y=y, label = "**"),
inherit.aes = FALSE)+
geom_line(data=tibble(x=c(1.929,2.22), y=c(33,33)),
aes(x=x, y=y), inherit.aes = FALSE) +
geom_text(data=tibble(x=2.0745, y = 34.5),
aes(x=x, y=y, label = "ns"),
inherit.aes = FALSE)+
geom_line(data=tibble(x=c(0.77,1.22), y=c(40,40)),
aes(x=x, y=y), inherit.aes = FALSE) +
geom_text(data=tibble(x=1, y = 41.5),
aes(x=x, y=y, label = "ns"),
inherit.aes = FALSE)

Adding texture to plot based on a condition in R

From the following dataframe df:
df <- data.frame(Date=1:5,
Cat1=c(1,0,1,0,0),
Cat2=c(1,1,1,0,0),
Cat3=c(0,1,1,0,1),
Cat4=c(0,0,1,1,0),
Mask=c(0,1,1,0,0))
df <- tidyr::pivot_longer(df, -1)
A tile plot is plotted as follows:
ggplot(df%>%filter(name!="Mask"),
aes(x = Date, y = factor(name, levels = rev(unique(name))),
fill = as.factor(value))) +
geom_tile(color = "black") +
scale_fill_manual(values = c("white", "grey50")) +
theme_void() +
theme(legend.position = "none",
axis.text = element_text(size = 15),
axis.title.x = element_text(size = 15),
plot.margin = margin(20, 20, 20, 20))
with the following output:
In ggplot, How it is possible to implement a texture by using the column Mask==1 in order to fill the Date?
Try the (not on CRAN) ggpattern-package
library(ggplot2)
#remotes::install_github("coolbutuseless/ggpattern")
library(ggpattern)
# set what cells need to be hatched
df <- df %>%
mutate(hatch = ifelse(Date %in% c(2,3), "yes", "no"))
ggplot(df%>%filter(name!="Mask"),
aes(x = Date, y = factor(name, levels = rev(unique(name))),
fill = as.factor(value), pattern = hatch)) +
geom_tile_pattern(pattern_color = "black",
pattern_fill = "black",
pattern_angle = 45,
pattern_density = 0.1,
pattern_spacing = 0.025,
pattern_key_scale_factor = 0.5) +
geom_tile(color = "black", alpha = 0.5) +
scale_pattern_manual(values = c(yes = "stripe", no = "none")) +
scale_fill_manual(values = c("white", "grey50")) +
theme_void() +
theme(legend.position = "none",
axis.text = element_text(size = 15),
axis.title.x = element_text(size = 15),
plot.margin = margin(20, 20, 20, 20))

Changing x axis on my plot to fit in one more value: xlim, scale_x_continuous not working

I created a cleveland dot plot for my data, but it stops a bit shorter than the last data point.
I would like it to end on 7000. I tried to use xlim(1000,7000) and scale_x_continuous(breaks = seq(1000, 7000, by = 1000) but it doesnt work. My code:
ggplot(tidydf, aes(Genome_size, `Trio_number`, color = Group)) +
geom_point() + geom_line(aes(group = Trio_number), color = 'grey30') +
scale_y_continuous(breaks = seq(0, 20, by = 1)) + scale_x_continuous(breaks = seq(1000,
7000, by = 1000) +
ylab("Trio number") + xlab("Genome size (kb)") + theme_dotplot + theme(legend.position =
"bottom") + scale_color_brewer(palette = "Set2") + theme(legend.title=element_blank()) +
guides(colour = guide_legend(override.aes = list(size=4))) +
theme(legend.key=element_rect(fill='grey96')) +
theme(plot.background = element_rect(fill = 'grey96')) + theme(legend.title =
element_text(size=10)) + theme(text=element_text(size=12, family="Gujarati Sangam MN"))
+ theme(axis.title.x = element_text(vjust = 0, size = 12), axis.title.y =
element_text(vjust = 2, size = 12)) + theme(axis.text = element_text(color = "black",
size = 9))
Reproducible data:
library(ggplot2)
library(scales)
set.seed(8675309)
tidydf <- data.frame(
Genome_size = sample(1000:7000, 30, replace = T),
Trio_number = sample(1:20, 30, replace = T),
Group = sample(c('Free-living', 'Gut', 'Pathogen'), 30, replace = T)
)
p <-
ggplot(tidydf, aes(Genome_size, `Trio_number`, color = Group)) +
geom_point() +
scale_y_continuous(breaks = seq(0, 20, by = 1)) +
ylab("Trio number") + xlab("Genome size (kb)") +
theme_light() +
scale_x_continuous(labels = comma) +
scale_color_brewer(palette = "Accent") +
guides(colour = guide_legend(override.aes = list(size=4))) +
theme(
legend.position = "bottom",
legend.key=element_rect(fill='gray96'),
plot.background = element_rect(fill = 'gray96'),
legend.title =element_text(size=10),
text=element_text(size=12),
axis.title.x = element_text(vjust = 0, size = 11),
axis.title.y = element_text(vjust = 2, size = 11),
axis.text = element_text(color = "black", size = 9),
# to make the theme look more similar to OP example
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
p
Thanks!
I think it would work by adding both limits = c(1000, 7000) and breaks = seq(1000, 7000, by = 1000) inside the scale_x_continuous call:
library(ggplot2)
library(scales)
set.seed(8675309)
tidydf <- data.frame(
Genome_size = sample(1200:6800, 30, replace = T),
Trio_number = sample(1:20, 30, replace = T),
Group = sample(c('Free-living', 'Gut', 'Pathogen'), 30, replace = T)
)
ggplot(tidydf, aes(Genome_size, `Trio_number`, color = Group)) +
geom_point() +
geom_line(aes(group = Trio_number), color = 'grey30') +
scale_y_continuous(breaks = seq(0, 20, by = 1)) +
ylab("Trio number") + xlab("Genome size (kb)") +
theme_light() +
scale_x_continuous(labels = comma,
limits = c(1000, 7000),
breaks = seq(1000, 7000, by = 1000)) +
scale_color_brewer(palette = "Accent") +
guides(colour = guide_legend(override.aes = list(size=4))) +
theme(
legend.position = "bottom",
legend.key=element_rect(fill='gray96'),
plot.background = element_rect(fill = 'gray96'),
legend.title =element_text(size=10),
text=element_text(size=12),
axis.title.x = element_text(vjust = 0, size = 11),
axis.title.y = element_text(vjust = 2, size = 11),
axis.text = element_text(color = "black", size = 9),
# to make the theme look more similar to OP example
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()
)
Created on 2021-03-22 by the reprex package (v1.0.0)

Resources