簡體   English   中英

在ggplot2中將離散計數數據繪制為點的“裝訂”

[英]Plotting discrete count data as “staple” of points in ggplot2

我的目標是繪制一些樂隊在音樂節上的演出頻率。 基本上,該圖應如下所示:

ggplot(plot.df2,aes(reorder(bands,count),count))+ geom_point()+ coord_flip()+ theme_bw()

在此處輸入圖片說明

但是我想每次都說一點,樂隊在那里演出。 這將是這樣的“主食”:

ggplot(plot.df2,aes(count))+ geom_dotplot()+ coord_flip()+ theme_bw()

在此處輸入圖片說明

ggplot2中可能嗎?

這是一些示例數據:

bands<-c("Queens of the Stone Age","The Sounds","Beatsteaks","Billy Talent","Donots","The Hives","Tocotronic")
count<-c(6,6,5,5,5,5,5)
plot.df<-as.data.frame(cbind(bands,count))

您可以執行此操作,但是需要一些手動調整刻度才能看起來不錯。

plot.df <- data.frame(band = rep(bands, count),
                      count = unlist(lapply(count, seq_len)))
ggplot(plot.df, aes(x = count, y=band)) +
    geom_point() + scale_x_continuous(limits=c(0, 10), breaks=seq(0, 10, by=2)

在此處輸入圖片說明

暫無
暫無

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

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