改变标题的位置

时间:2016-01-30 10:32:49

标签: r

我正在尝试使用以下代码使用R绘制饼图。标题远离饼图。我想在标题下方得到饼图。我怎么能这样做?

x <-  c(632,20,491,991,20)
y <- c(37376,41770,5210,5005,3947)
names <- c("alpha","beta","gamma","delta","omega")
par(mfrow=c(1,2))
pie(x, names, col = c("red", "yellow", "blue", "green", "cyan"), main="PIE CHART 1")
pie(y, names,col = c("red", "yellow", "blue", "green", "cyan"),  main="PIE CHART 2")

1 个答案:

答案 0 :(得分:2)

x <-  c(632,20,491,991,20)
y <- c(37376,41770,5210,5005,3947)
names <- c("alpha","beta","gamma","delta","omega")
par(fig=c(0,0.5,0,1))
pie(x, names, col = c("red", "yellow", "blue", "green", "cyan"))
title("CHART 1", line=-3)
par(fig=c(0.5,1,0,1),new=TRUE)
pie(y, names,col = c("red", "yellow", "blue", "green", "cyan"))
title("CHART 2", line=-3)

的改变:

  • Par - 将控制权改为fig = c(x,x,y,y),以指定您希望每个绘图占据窗口的一部分,以便在我每个饼图占用时情节窗口的一半
  • Par new = TRUE表示您想要第二个情节&#34;覆盖&#34;
  • 标题 - 与情节,线= x状态分开,你想要标题所在的位置,玩各种各样的数字 - 直到你得到你想要的东西

作为替代方案,您还可以继续使用mfrow

par(mfrow=c(1,2))
pie(x, names, col = c("red", "yellow", "blue", "green", "cyan"))
title("PIE CHART 1", line=-1)
pie(y, names, col = c("red", "yellow", "blue", "green", "cyan"))
title("PIE CHART 2", line=-1)