Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 转换为jpg格式时图例过大的ggplot2图像_R_Plot - Fatal编程技术网

R 转换为jpg格式时图例过大的ggplot2图像

R 转换为jpg格式时图例过大的ggplot2图像,r,plot,R,Plot,我正在制定一个计划,提交给一家学术期刊。 我使用png()函数进行抗锯齿,但绘图中的图例太大 请参考下面的示例代码和绘图 posn.d <- position_dodge(0.1) plot_test <- ggplot(mtcars, aes(factor(gear), hp, shape = factor(am)))+ ylab("HP")+ stat_summary(fun.y = mean, geom = "point", position = posn.d, aes

我正在制定一个计划,提交给一家学术期刊。 我使用png()函数进行抗锯齿,但绘图中的图例太大

请参考下面的示例代码和绘图

posn.d <- position_dodge(0.1)
plot_test <- ggplot(mtcars, aes(factor(gear), hp, shape = factor(am)))+
  ylab("HP")+
  stat_summary(fun.y = mean, geom = "point", position = posn.d, aes(shape = factor(am)), size = 1)+
  stat_summary(fun.y = mean, geom = "line", position = posn.d, aes(group = factor(am), linetype = factor(am)), size = 0.4)+
  stat_summary(fun.data = mean_se, fun.args = list(mult = 1), geom = "errorbar", width = 0.1, position =posn.d, size=0.3)+
  theme(legend.key = element_rect(colour = "white"), panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        axis.title.y=element_text(vjust=1,face="bold",size=6), axis.title.x = element_blank(),
        axis.text.x=element_text(size=6, face = "bold"), axis.text.y=element_text(size=6, face = "bold"),
        axis.line.x=element_line(size=0.2),axis.line.y=element_line(size=0.2),axis.ticks=element_line(size=0.2),
        plot.title=element_text(hjust=0,vjust=2,face="bold", size=3))+
  scale_linetype_manual(name = "AM", labels = c("am0", "am1"), values = c("solid", "dotted"))+
  scale_shape_manual(name = "AM", labels = c("am0", "am1"), values = c(16, 15))+
  scale_x_discrete(labels = c("three", "four", "five"))


png(width = 100, height = 35, units="mm", filename = "test.jpg", type = "cairo", antialias = "subpixel", family = "malgun", res = 300)
plot_test
dev.off()
在主题()中。 但图例文本和标题之间的空间仍然太大,看起来难以控制

谁能在不改变整个图像大小或分辨率的情况下帮助我?
(因为无法自由控制大小和分辨率以符合该杂志的指导原则。)

FYI-在
png
调用中为其提供.jpg扩展名不会使生成的图像格式成为jpeg(无论如何,这对于此类图形都是不合适的)。结果仍然是一个png文件。我不知道。其实我对图像格式的细节了解不多。无论如何,图像都保存为*.jpg。谢谢你提供的信息。:)
legend.title = element_text(size = 4, face = "bold"), legend.text = element_text(size = 4)