2016-07-29 140 views
3

我想要一个圆形条形图,像图所示:极地柱状图中,与最里面的圆空基于R

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)) 
+1

看起来我们错过了您的数据。对于这种类型的问题,SO需要一个完全可重复的例子,以便我们可以帮助您。 –

+0

我添加了数据。它只是一个简单的频率表。 – 204

+1

谢谢。他们会说要以可复制的方式发布它(这意味着你可以将它读入R)。你可能想使用'dput(the_data)'。 –

回答

3

通过先创建一个柱状图中,然后将其转换为极坐标(这是罚款)出示你的阴谋。如果你想让条形图不能从极坐标图的中心开始,那么你需要确保它们不在条形图的底部开始。

我的意思是最简单的解释是通过实际显示它。首先,我创建了柱状图中相同的方式,你做什么,但我延长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的值。