Reputation: 299
I have the following data frame:
> 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))
I would like to have a bubble chart for my df with circles labeling with each verb in the text column and also the number of IDs that are related to each verb in the text column. This is the code I have for the circles but I don't know how to do the labeling:
> 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()
Upvotes: 1
Views: 1137
Reputation: 1321
You create a data.frame
for your labels with the appropriate x and y coordinate and use 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))
For the Text
and ID
, you can do:
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))
Upvotes: 2