使用下面的代码,我可以生成一个很好的相关图。
library(corrplot)
df <- data.frame(A=1:10,B=rnorm(10)*(1:10),C=1:10,D=runif(10)*1:10)
df
corrplot(cor(df))
添加bg="black"
参数会将图表内的颜色更改为黑色。
df <- data.frame(A=1:10,B=rnorm(10)*(1:10),C=1:10,D=runif(10)*1:10)
df
corrplot(cor(df),bg="black")
现在如果我想将整个图形窗口设置为黑色,这应该可以工作:
par(bg="black")
df <- data.frame(A=1:10,B=rnorm(10)*(1:10),C=1:10,D=runif(10)*1:10)
df
corrplot(cor(df),bg="black")
但事实并非如此。如何让整个绘图窗口变黑?
答案 0 :(得分:1)
这是一个两步的方式:
# First, we need to plot once, to get the extremes of
# the user coordinates of the plotting region, as set
# by the corrplot function
corrplot(cor(df))
# The extremes are stored
usr <- par("usr")
# New empty plotting window
plot.new()
# Set the new extremes
par(usr=usr)
# Plot a rectangle filled in black, covering the whole plotting window
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "black")
# Finally, plot the corrplot
corrplot(cor(df), bg="black", add = TRUE)