gpt4 book ai didi

r - 改变标题的位置

转载 作者:行者123 更新时间:2023-12-02 01:29:13 24 4
gpt4 key购买 nike

我正在尝试通过以下代码使用 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")

最佳答案

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 表示您想要“覆盖”第二个绘图
  • 标题 - 与情节分开,line=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)

关于r - 改变标题的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35100677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com