所以这与此非常相关question https://stackoverflow.com/questions/7001799/ggplot2-curly-braces-on-an-axis和这个answer https://stackoverflow.com/a/33544572/1582926是一个很好的解决方案。
问题是,当我尝试使用 ggsave 导出绘图时,大括号不存在。
example:
library(ggplot2)
library(grid)
library(pBrackets)
x <- c(runif(10),runif(10)+2)
y <- c(runif(10),runif(10)+2)
the_plot <- qplot(x=x,y=y) +
scale_x_continuous("",breaks=c(.5,2.5),labels=c("Low types","High types") ) +
theme(axis.ticks = element_blank(),
axis.ticks.length = unit(.85, "cm"))
the_plot
grid.locator(unit="native")
bottom_y <- 284
grid.brackets(220, bottom_y, 80, bottom_y, lwd=2, col="red")
grid.brackets(600, bottom_y, 440, bottom_y, lwd=2, col="red")
ggsave("test.png",width = 4, height = 2.5)
我不愿意使用 RStudio 导出按钮,因为它无法正确导出我的主题字体大小等。我还需要高于 76 dpi 的分辨率。我需要一个解决方案来向 ggplot2 图形添加大括号并能够使用 ggsave 保存它。