I'm want to remove only the top part of my graph.
I found some directions here and here. However, they remove all the borders or the top and left.
I know that I should probably use the argument panel.border
with element_blank()
or element_rect()
but I cannot find the correct way to define it.
I'm looking for this:
library(tidyverse)
mtcars %>%
ggplot(aes(factor(cyl), disp)) +
geom_boxplot() +
jtools::theme_apa() +
theme(
panel.border = element_blank())
Will results with:
One more option (with some advice from Tjebo)
library(tidyverse)
mtcars %>%
ggplot(aes(factor(cyl), disp)) +
geom_boxplot() +
scale_y_continuous(sec.axis = sec_axis(~ .))+
jtools::theme_apa() +
theme(
axis.line.x.bottom = element_line(color = 'black'),
axis.line.y.left = element_line(color = 'black'),
axis.line.y.right = element_line(color = 'black'),
axis.text.y.right = element_blank(),
axis.ticks.y.right = element_blank(),
panel.border = element_blank())
Using one of the references you have posted, you end up in this script (thanks to Rudolf Cardinal and Alex Holcombe). You can use the function theme_border()
to plot the borders you want. To do so, just download the script provided in the link, put it in your working directory and execute the following code:
library(tidyverse)
library(grid)
source("rnc_ggplot2_border_themes_2013_01.r")
mtcars %>%
ggplot(aes(factor(cyl), disp)) +
geom_boxplot() +
jtools::theme_apa() +
theme(
panel.border = theme_border(type = c("bottom","right","left")))
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With