如何将光盘上的R饼图保存为.jpg?

时间:2014-12-17 10:37:17

标签: r charts save

饼图示例:

slices <- c(10, 12, 4, 16, 8) 
lbls <- c("US", "UK", "Australia", "Germany", "France")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct) # add percents to labels 
lbls <- paste(lbls,"%",sep="") # ad % to labels 
pie(slices,labels = lbls, col=rainbow(length(lbls)),main="Pie Chart of Countries") 

jpeg(filename="Pie chart.jpg",width=480,height=480)
plot()
dev.off()

以上代码创建空白.jpg。我应该在plot()中写什么参数......如果这是正确的。

1 个答案:

答案 0 :(得分:2)

将pie(...)行放在plot()现在

的位置
jpeg(filename="Pie chart.jpg",width=480,height=480)
pie(slices,labels = lbls, col=rainbow(length(lbls)),main="Pie Chart of Countries") 
dev.off()