将geom_bar添加到圆形图ggplot2 [英] add geom_bar to circular plot ggplot2

查看:71
本文介绍了将geom_bar添加到圆形图ggplot2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的数据框:

I have a data frame that looks like so:

dat<-structure(list(x = 1:14, y = c(1.26071476002898, 1.97600316441492, 
2.41629009067185, 3.48953782319898, 10, 8.49584395945854, 3.80688560348562, 
3.07092373734549, 2.96665740569527, 2.73020216450355, 2.39926441554745, 
2.4236111796397, 2.63338121290737, 2.13662243060685)), .Names = c("x", 
"y"), row.names = c(NA, -14L), class = "data.frame")

x         y
1  1.260715
2  1.976003
3  2.416290
4  3.489538
5 10.000000
6  8.495844
7  3.806886
8  3.070924
9  2.966657
10  2.730202
11  2.399264
12  2.423611
13  2.633381
14  2.136622

我正在尝试在ggplot2中创建一个圆图,其中将圆分为我拥有的14个数据点,每个圆弧的长度对应于y的值.像这样:

I'm trying to create a circular plot in ggplot2 where the circle is divided into the 14 data points I have and the length of each of the arcs corresponds to the value of y. Something like this:

我的代码产生了一个非常奇怪的输出,条形图相互重叠.我到处搜索了修复它,但没有成功.这是我的代码:

My code produces a very weird output with the bars overlapping one another. I have searched everywhere to fix it but no success. Here is my code:

ggplot(dat, aes(x, y)) + geom_bar(breaks = seq(1,14), width = 2, colour = "grey",         stat="identity") + coord_polar(start = 0) + scale_x_continuous("", limits = c(1, 14), breaks = seq(1, 14), labels = seq(1, 14))

请帮助我...在此先感谢...

Please help me… thanks in advance...

推荐答案

这是因为您指定了 width = 2 .这样会产生重叠.

It's because you specified width=2. This produces the overlap.

请注意,您不需要任何中断.

Note also that you don't need any breaks.

尝试一下:

library(ggplot2)

ggplot(dat, aes(x, y)) + 
  geom_bar(stat="identity") +
  coord_polar(start = 0) +
 scale_x_continuous("",breaks = seq(1, 14))

这篇关于将geom_bar添加到圆形图ggplot2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆