将绘图从R导出为PDF
我已经搜索了这个网站和其他网站,寻找答案,但似乎无法让代码的PDF部分正常工作,非常感谢您的帮助 此代码工作正常,它在RStudio输出中循环并为每个行业创建绘图:将绘图从R导出为PDF,r,pdf,plot,ggplot2,R,Pdf,Plot,Ggplot2,我已经搜索了这个网站和其他网站,寻找答案,但似乎无法让代码的PDF部分正常工作,非常感谢您的帮助 此代码工作正常,它在RStudio输出中循环并为每个行业创建绘图: gg <- list() #make the plots, facet by client on each page - works well for (p in 1:length(df)){ gg[[p]] <- ggplot(data = df[[p]], aes(x = MonthsAct
gg <- list()
#make the plots, facet by client on each page - works well
for (p in 1:length(df)){
gg[[p]] <- ggplot(data = df[[p]], aes(x = MonthsActive, y = Participation, color = CommClient)) +
ylim(0,1) + geom_line(size = 0.8) +
scale_x_continuous(limits = c(1,13)) +
facet_wrap(~ClientName, scales="fixed") +
scale_color_hue(l = 45) +
ggtitle(sprintf("Participation Rate for %s for First Year",params[p]))
plot(gg[[p]])
}
ggdev.off()需要在循环内dev.off()需要在循环内dev.off()需要在循环内dev.off()需要在循环内尝试使用ggsave
保存生成的绘图,cleaner使用IMO。对于网格图形,您应该使用print
notplot
尝试使用ggsave
保存生成的绘图,cleaner使用IMO。对于网格图形,您应该使用print
notplot
尝试使用ggsave
保存生成的绘图,cleaner使用IMO。对于网格图形,您应该使用print
notplot
尝试使用ggsave
保存生成的绘图,cleaner使用IMO。对于网格图形,您应该使用print
notplot
gg <- list()
#make the plots, facet by client on each page
for (p in 1:length(df)){
#set the file path by name - when using print looks fine
myPath <- file.path("Q:","DataScience", "ParticipationPlots", paste(params[p], ".pdf", sep=""))
#set pdf as device and make individual PDFs
pdf(file = myPath, onefile = F, paper = "USr", width = 11, height = 8.5)
#this code is the same as above that works except for dev.off() at end
gg[[p]] <- ggplot(data = df[[p]], aes(x = MonthsActive, y = Participation, color = CommClient)) +
ylim(0,1) + geom_line(size = 0.8) +
scale_x_continuous(limits = c(1,13)) +
facet_wrap(~ClientName, scales="fixed") +
scale_color_hue(l = 45) +
ggtitle(sprintf("Participation Rate for %s for First Year",params[p]))
plot(gg[[p]])
}
dev.off()