簡體   English   中英

將geom_bar添加到圓形圖ggplot2

[英]add geom_bar to circular plot ggplot2

我有一個看起來像這樣的數據框:

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的值。 像這樣: 在此處輸入圖片說明

我的代碼產生了一個非常奇怪的輸出,條形圖相互重疊。 我到處搜索過修復它,但沒有成功。 這是我的代碼:

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 這產生了重疊。

另請注意,您無需breaks

嘗試這個:

library(ggplot2)

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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM