gpt4 book ai didi

r - 极柱图,最内圈为空 使用 R

转载 作者:行者123 更新时间:2023-12-01 12:26:46 25 4
gpt4 key购买 nike

我想要一个圆形条形图,如下所示:

enter image description here
但现在,我只有:
enter image description here

为此,我在 R 中使用了以下代码:

require(ggplot2)
ggplot(PolarPlot,aes(x,y,
fill=x))+
geom_bar(width=1,stat="identity")+
coord_polar() + xlab("")+ylab("")+
theme(legend.position = "none" , axis.text.y = element_blank() ,
axis.ticks = element_blank()

有人可以告诉我需要进行哪些修改才能获得所需的图表吗?

数据如下:
PolarPlot <- structure(list(x = structure(1:7, .Label = c("Class1", "Class2", 
"Class3", "Class4", "Class5", "Class6", "Class7"), class = "factor"),
y = c(2L, 8L, 17L, 56L, 28L, 7L, 2L)), .Names = c("x", "y"),
class = "data.frame", row.names = c(NA, -7L))

最佳答案

您首先创建一个条形图,然后将其转换为极坐标(这很好)来生成您的图。如果您不希望条形图从极坐标图中的中心开始,那么您需要确保它们不会从条形图中的底部开始。

我的意思最容易通过实际展示来解释。首先,我以与您相同的方式创建条形图,但我扩展了 y 轴以达到负值:

p <- ggplot(PolarPlot, aes(x, y, fill=x)) +
geom_bar(width=1,stat="identity") +
xlab("") + ylab("") +
theme(legend.position = "none" , axis.text.y = element_blank() ,
axis.ticks = element_blank()) +
scale_y_continuous(limits = c(-50, 60))

enter image description here

当我切换到极坐标时,条形图下端的间隙转换为极坐标图中心的间隙:
p + coord_polar()

enter image description here

您可以通过使用用于 limits 的值来修改中心间隙的大小。在 scale_y_continuous() .

关于r - 极柱图,最内圈为空 使用 R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38659150/

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