Using R to make a barplot with a specific width?

荒凉一梦 提交于 2019-12-11 16:27:35

问题


I would like to use R to make a barplot of ~100,000 numerical entries. The plot will be dense, which is what I want. So far I am using the following code:

sample_var <- c(2,5,3,2,3,2,6,10,20,...)  #Filled with 100,000 entries
barplot(sample_var)

The resulting plot is just what I want, but it is a square, whereas I want a long rectangle. Is there a way to set the dimensions of the barplot? I would like to specific an aspect ratio of 10:1 for length x height, or a specific pixel setting of 1000px x 10px. I tried using xlim in the barplot function statement, but get an "invalid xlim" warning.

Any help is appreciated!


回答1:


Set the width and hight when outputting to a file:

png(filename="figures.png", width=800, height=200, bg="white") 
sample_var <- c(2,5,3,2,3,2,6,10,20)
barplot(sample_var)
dev.off()


来源:https://stackoverflow.com/questions/20355679/using-r-to-make-a-barplot-with-a-specific-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!