[英]Bubble chart without axis with labels in R
我有以下數據框:
> dput(df)
structure(list(text = structure(c(9L, 10L, 1L, 7L, 5L, 12L, 1L,
11L, 5L, 8L, 2L, 13L, 2L, 5L, NA, 6L, 13L, 4L, NA, 5L, 4L, 3L
), .Label = c("add ", "change ", "clarify", "correct", "correct ",
"delete", "embed", "follow", "name ", "remove", "remove ", "specifiy ",
"update"), class = "factor"), ID = c(1052330L, 915045L, 931207L,
572099L, 926845L, 510057L, 927946L, 490640L, 928498L, 893872L,
956074L, 627059L, 508649L, 508657L, 1009304L, 493138L, 955579L,
144052L, 1011166L, 151059L, 930992L, 913074L)), .Names = c("text",
"ID"), class = "data.frame", row.names = c(NA, -22L))
我想為我的df制作一個氣泡圖,在圓圈中標注帶有文本列中每個動詞的標簽,以及與文本列中每個動詞相關的ID數。 這是我為圈子准備的代碼,但是我不知道如何做標簽:
> library(packcircles)
> library(ggplot2)
> packing <- circleProgressiveLayout(df)
> dat.gg <- circleLayoutVertices(packing)
> ggplot(data = dat.gg) +geom_polygon(aes(x, y, group = id, fill = factor(id)), colour = "black",show.legend = FALSE) +scale_y_reverse() +coord_equal()
您使用適當的x和y坐標為標簽創建一個data.frame
並使用geom_text
library(ggplot2)
packing <- circleProgressiveLayout(df)
dat.gg <- circleLayoutVertices(packing)
cbind(df, packing) -> new_df
ggplot(data = dat.gg) +geom_polygon(aes(x, y, group = id, fill = factor(id)), colour = "black",show.legend = FALSE) +
scale_y_reverse() +coord_equal() +geom_text(data = new_df, aes(x, y,label = text))
對於Text
和ID
,您可以執行以下操作:
new_df$text2 <- paste0(new_df$text,"\n",new_df$ID)
ggplot(data = dat.gg) +geom_polygon(aes(x, y, group = id, fill = factor(id)), colour = "black",show.legend = FALSE) +
scale_y_reverse() +coord_equal() +geom_text(data = new_df, aes(x, y,label = text2))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.