r - 将 geom_bar 添加到圆形图 ggplot2

标签 r plot ggplot2 geom-bar

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

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 的值。像这样:enter image description here

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

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

请帮助我...提前致谢...

最佳答案

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

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

试试这个:

library(ggplot2)

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

enter image description here

关于r - 将 geom_bar 添加到圆形图 ggplot2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26204826/

相关文章:

R sort() 忽略 Ubuntu 16.04 上的语言环境

r - 如何拆分数据框列并相应地复制行? [复制]

r - 获取因子频率的直方图(摘要)

python - 使用 Pandas 的 matplotlib 格式化问题

r - 使用 Lattice (panel.smoother) 或 ggplot 提取用于获得最佳拟合的方程

R Shiny : not sure why ggplot is failing

java - 安装 rJava - "configure: error: One or more JNI types differ from the corresponding native type"

r - 在ggvis中动态选择组

没有标签的Android GraphView 2

r - 如何在 R 中的 PAM 中获取主成分数据