R输出图形

这篇博文写的很好 https://www.r-bloggers.com/exporting-nice-plots-in-r/
介绍的 Inkscape 也很好用,解决了之前IGV输出SVG图片的问题。导入PPT只显示一半。用Ai cc 打开,报错。“往返Tiny时剪贴将丢失”,只有框架没有图

There are two main problems when exporting graphics from R:

  • Anti-aliasing is not activated in Windows R (this does not apply to Linux or Mac) – windows下没有反锯齿设置,解决:library(Cairo)
  • When increasing the resolution the labels automatically decrease and become unreadable –分辨率升高,标签会自动缩小

If we want to increase the resolution of the plot we can’t just change the resolution parameter:
We also have to change the point size, the formula is size * new resolution DPI / 72 DPI:

If we double the image size we also need to double the point size:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2/
# exporting nice plot https://www.r-bloggers.com/exporting-nice-plots-in-r/
# library
library(ggplot2)

# create a data frame
variety=rep(LETTERS[1:7], each=40)
treatment=rep(c("high","low"),each=20)
note=seq(1:280)+sample(1:150, 280, replace=T)
data=data.frame(variety, treatment , note)


# grouped boxplot
ggplot(data, aes(x=variety, y=note, fill=treatment)) +
geom_boxplot()

# One box per treatment
ggplot(data, aes(x=variety, y=note, fill=treatment)) +
geom_boxplot() +
facet_wrap(~treatment)
# one box per variety
ggplot(data, aes(x=variety, y=note, fill=treatment)) +
geom_boxplot() +
facet_wrap(~variety, scale="free")