So this is very relevant to this question and this answer is an excellent solution.
The problem is that when I try to export the plot using ggsave the curly braces aren\
Well I figured you could do something with devices, as an alternative to ggsave
, and I finally got this to work. It was more effort than it should have been because R-Studio somehow gets confused about which devices are actually open or closed (off). So you have to reset your R session sometimes. Checking dev.list()
a lot helps. Sort of...
But after a bit of testing this sequence works fairly reliably.
I tested it with jpeg too because I can look at the resolution with the file property command in windows to see that the resolution I specified (200 ppi) is getting through:
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
# User has to click here to specify where the brackets go
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")
#dev.copy(png,"mypng.png",height=1000,width=1000,res=200)
dev.copy(jpeg,"myjpg.jpg",height=1000,width=1000,res=200)
dev.off()
The image:
The properties: