[英]Plotting fixed plot area
I have simple question, how can I plot fixed height barplots, ie stretching the plot area only change margins not the bararea, like the following: 我有一个简单的问题,我如何绘制固定高度的条形图,即拉伸绘图区域只改变边距而不是bararea,如下所示:
> A <- 4
> plot (A)
> barplot(A, col = "green4")
When I strech are, bar area also get increases. 当我拉伸时,酒吧区域也会增加。
Edits: I want to keep the box size constant even the plot gets stretched. 编辑:我想保持盒子大小不变,即使情节得到拉伸。
by splitting the screen into multiple parts, you can achieve that partially: 通过将屏幕分成多个部分,您可以部分实现:
split.screen(c(3,1))
A <- 4
barplot(A, col="green4")
Are you looking to just expand the y axis. 您是否希望扩展y轴。 Look at
ylim
? 看看
ylim
?
What you might be looking for is to fix your aspect ratio. 您可能正在寻找的是修复纵横比。 This can be achieved using
asp
: 这可以使用
asp
实现:
barplot(A, col = "green4", asp = 1)
See also this post to R-help . 另见R-help的这篇文章 。
On a more philosophical note, when the height of the bar changes, there is no change in surface area. 从更哲学的角度来看,当条形高度发生变化时,表面积没有变化。
barplot
only draws a sequence of bars, where the x
axis is an ordinal (ordered categorical) variable which makes it impossible to calculate a surface area. barplot
仅绘制一系列条形图,其中x
轴是序数(有序分类)变量,这使得无法计算表面区域。 The height of the bar is the only changing variable. 条形的高度是唯一变化的变量。 I would recommend drawing these kinds of timeseries using a simple line plot.
我建议使用简单的线图绘制这些时间序列。
So instead of: 所以代替:
a = runif(100)
b = 1:100
barplot(a)
use: 采用:
plot(b, a, type = "l")
or switch to my favorite plotting package, ggplot2
: 或切换到我最喜欢的绘图包,
ggplot2
:
require(ggplot2)
theme_set(theme_bw())
qplot(b, a, geom = "line")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.