【发布时间】:2017-03-20 14:24:13
【问题描述】:
我正在生成一个ggplot plot 并将其保存为.png 图像。虽然在 Rstudio 中生成的绘图会根据 y 轴的值进行拉伸,但当我将其保存为 .png 时,我会得到一个正方形的图像。
如何以.png 形式自动获得最佳拉伸图像?
# Function to store ggplot plot object as .png image file
savePlot <- function(myPlot, filename) {
png(filename)
print(myPlot)
dev.off()
}
# ggplot object
normalized_bar_plot = ggplot(dat, aes(factor(temp), norm, fill = type)) +
geom_bar(stat="identity", position = "dodge") + ylab("Normalized count")+xlab(features[i])+
scale_fill_brewer(palette = "Set1")
filename = paste0("image_", features[i], ".png")
savePlot(normalized_bar_plot, filename)
【问题讨论】: