我想用多个图形来演示R的par()图形参数命令,所以我做了一个简单的2×2布局,这个布局非常好。我添加了一个par (col = "green")命令来生成一个barplot()和三个hist()图,但是它没有做任何我能看到的事情。
这是我的R脚本,这应该是安全的,因为我保存和恢复您的图形设置在顶部和底部。为长时间的dput()表示歉意,但我想让您知道我所拥有的数据。
savedGraphicsParams <- par(no.readonly=TRUE)
layout(matrix(c(1, 2, 3, 4), nrow=2, byrow=TRUE))
par(col = "green") # doesn't work
attach(Lakes)
# GRAPH 1:
barplot(table(N_of_Fish), main="Fish", xlab = "No. of Fish")
# GRAPH 2:
hist(Elevation, main = "Elevation", xlab = "ft")
# GRAPH 3
hist(Surface_Area, main="Surface Area", xlab = parse(text="ft^2"))
# GRAPH 4
hist(`, main="Max Depth", xlab = "ft")
detach(Lakes)
par(savedGraphicsParams) # Reset the graphics发布于 2019-02-21 00:49:08
tl;博士不幸的是,据我所知,您不能这样做;您必须在单独的情节调用中使用col=。翻阅?par,我们发现:
几个参数只能通过调用“()”来设置:. 其余的参数也可以将设置为参数(通常是通过‘.’)高层次的情节函数. 然而,,见关于“bg”、“cex”、“col”、“lty”、“lwd”和“pch”的评论,这些评论可以被看作是对某些绘图函数的,而不是图形参数。
(强调后加)。
我把这解释为bg等人的意思。对par()的调用不能全局设置(即使在?par中描述和讨论了这些调用),但是必须将设置为单个绘图调用的参数。我会以这种方式编写代码(同时也避免使用attach(),即使在它自己的手册页中也不建议使用.)
plot_col <- "green"
with (Lakes,
{
barplot(table(N_of_Fish), main="Fish", xlab = "No. of Fish", col=plot_col)
hist(Elevation, main = "Elevation", xlab = "ft", col=plot_col)
hist(Surface_Area, main="Surface Area", xlab = parse(text="ft^2"), col=plot_col)
hist(Maximum_Depth, main="Max Depth", xlab = "ft", col=plot_col)
})https://stackoverflow.com/questions/54797418
复制相似问题