【发布时间】:2019-06-26 06:07:38
【问题描述】:
我的 R 线图中的边距有问题...我知道网站上有很多与此相关的问题,但似乎没有一个问题能说得通,所以我想我会问特别是包含的细节......如果描述性过度/冗长,我也深表歉意!
我在时间点而不是 0:3 绘制带有多条线 (4) 和自定义刻度线(字符/描述性信息)的 R 线图。一切都很好,除了边距。
因此,首先将刻度标签从屏幕上删除。但是,轴对齐、图例显示和所有数据点显示等。否则一切看起来都是正确的。
这里我设置mar = c(5, 4.1, 4.1, 4.0)
我尝试更改以便通过以下方式显示标签:
mar = c(5, 4.1, 4.1, 4.0) + x),对 x 使用多个值(0.5、1.0、2.5 等)。
这会更改轴,使其不对齐,图形被切断等,并且标签再次离开屏幕。
接下来我尝试使用以下方法更改 dev.new(...) 选项:
dev.new(width=4, height=3, unit="in") 和 w 和 h 的其他值。仍然没有解决方案...对齐全部关闭,x 轴丢失,轴标签和刻度标签关闭等。
非常感谢任何帮助。我知道在这样的例子中使用它可能是一个挑剔的情节,但在这个例子中我更喜欢 R 情节而不是 ggplot。
提前谢谢你...
这是可比较的 R 代码:
bird <- c ("2", "4", "3.5", "8")
dog <- c ("8", "6", "10", "4")
fish <- c("10", "8", "5", "1")
cat <- c("12", "6", "3", "1")
time = c("0", "1", "2", "3")
dev.new()
plot(time, bird, type="o", col="darkblue", xlab="time points", ylab="average scores of pets", main = "average pet scores over time", ylim=c(0, 15), cex.main=1.2, axes=FALSE)
par(las=2, mar = c(5, 4.1, 4.1, 4.0))
axis(1, at=0:3, labels= c("pre-lim", "first appointment", "3 month check-up", "12 month check-up"))
axis(2)
lines(time, dog, type="o", col="forestgreen")
lines(time, fish, type="o", col="cornflowerblue")
lines(time, cat, type="o", col="darkturquoise")
legend (2.25, 14.3, legend = c("bird", "dog", "fish", "cat"), fill= c("darkblue", "forestgreen", "cornflowerblue", "darkturquoise"))
【问题讨论】:
标签: r plot margin axis-labels line-plot