I have the following dataframe:
data <- data.frame(x = c(5,1,3,2,5,7,12), y = c(5,7,6,1,3,5,6))
I can plot these coordinates with the ggplot function and draw a line between these coordinates:
ggplot(data, aes(x, y)) + geom_point(size = 3) + geom_line()
So far, no problems. But instead of a single line though the coordinates, I want that a line is drawn between all the coordinates. Creating a sort of spider web between all the coordinates. Is this possible in the ggplot2
package?
Using
base
plotting:Add bells and whistles to taste.
You may also use the
FUN
argument incombn
:If you want to do this in
ggplot2
, then you could usegeom_segment
for this. But before you can make such a plot, you have to create a dataframe which connencts each observation to the other observations. You could approach it as follows:which gives:
Used data:
Alternatively, you can also add the row-id on the fly without doing it beforehand: