the title inartful, let me explain. goal have line top of large "hold" circle (at 12:00) top of "back" circle (at 12:00), , on down. line bottom of large circle (6:00) bottom of next largest circle, , on. addition of such lines possible without placing segments manually? thank you.
# example data frame df <- data.frame(documents = c(1.5e5, .6e5, .3e5, .1e5), stages = c("hold", "back", "trust", "camp"), x = c(12, 18, 25, 35), y = c(10, 8, 7, 6)) library("ggplot2") library(ggthemes) ggplot(df, aes(x = x, y = y, size = documents)) + geom_point(color = "grey30", alpha = 0.3) + theme_tufte() + scale_size_area(max_size = 35) + geom_text(aes(label = stages), size = 6, color = "red") + theme(axis.text = element_blank()) + labs(x = "", y = "", fill = "documents") + theme(legend.position = "bottom") + xlim(8, 38) + ylim(5, 13)
here's attempt takes plot generated ggplot
draws lines inside viewport same scales ggplot plot panel. ggplot
's internal data gives size of circles in points - think. think radius of circle. top , bottom of circle, needed add , subtract "native" units "points" units. don't know of way in ggplot
proper, can done in grid
; hence viewports.
but note lines (and points) not on circumference of circles - not sure of reason.
i made 1 minor change ggplot - expand = c(0,0)
on 2 axes viewport can given same scales plot panel.
# example data frame df <- data.frame(documents = c(1.5e5, .6e5, .3e5, .1e5), stages = c("hold", "back", "trust", "camp"), x = c(12, 18, 25, 35), y = c(10, 8, 7, 6)) library("ggplot2") library(ggthemes) library(grid) p = ggplot(df, aes(x = x, y = y, size = documents)) + geom_point(color = "grey30", alpha = 0.3) + theme_tufte() + scale_size_area(max_size = 35) + geom_text(aes(label = stages), size = 6, color = "red") + theme(axis.text = element_blank()) + labs(x = "", y = "", fill = "documents") + theme(legend.position = "bottom") + scale_x_continuous(limits = c(8,38), expand = c(0,0)) + scale_y_continuous(limits = c(5,13), expand = c(0,0)) p # size of dots ggplot's internal data. # think "size" radius in "pts". g = ggplot_build(p) df$size = g$data[[1]]$size # set viewport plot panel current.vptree() # find plot panel downviewport("panel.6-4-6-4") # set scales in plot panel - see "limits" in ggplot pushviewport(dataviewport(yscale = c(5,13), xscale = c(8,38))) # draw points , lines grid.points(x = unit(df$x, "native"), y = unit(df$y, "native") + unit(df$size, "pt"), pch = 19, gp = gpar(col = "blue", cex = .5), default.units = "native") grid.points(x = unit(df$x, "native"), y = unit(df$y, "native") - unit(df$size, "pt"), pch = 19, gp = gpar(col = "blue", cex = .5), default.units = "native") grid.lines(x = unit(df$x, "native"), y = unit(df$y, "native") + unit(df$size, "pt"), gp = gpar(col = "blue", lwd = 2), default.units = "native") grid.lines(x = unit(df$x, "native"), y = unit(df$y, "native") - unit(df$size, "pt"), gp = gpar(col = "blue", lwd = 2), default.units = "native") popviewport() popviewport() popviewport()