使用R制作具有特定宽度的条形图? [英] Using R to make a barplot with a specific width?

查看:99
本文介绍了使用R制作具有特定宽度的条形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用R绘制一个〜100,000个数字条目的小节图.情节将是密集的,这就是我想要的.到目前为止,我正在使用以下代码:

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)

生成的图正是我想要的,但是它是一个正方形,而我想要一个长矩形.有没有一种方法可以设置条形图的尺寸?我想将长x高指定为10:1的宽高比,或将1000px x 10px设置为特定的像素.我尝试在barplot函数语句中使用 xlim ,但收到无效的xlim"警告.

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.

感谢您的帮助!

推荐答案

在输出到文件时设置 width hight :

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()

这篇关于使用R制作具有特定宽度的条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆