I have 4 species found in 5 samples in a plot. I want to visualize them in ggplot2 with latitude on x axis, longitude on y-axis; and their abundance essentially as the size coloured by species. I tried to work and got the following
lat <- c(1,2,3,4,5)
long <- c(13,2,7,5,15)
sp1 <- c(0,10,4,3,2)
sp2 <- c(20,10,14,0,1)
sp3 <- c(10,0,2,3,7)
sp4 <- c(2,0,0,0,12)
df <- data.frame(lat, long, sp1, sp2, sp3, sp4)
library(tidyr)
df.long <- gather(df,
key = "species",
value = "abundance",
sp1, sp2, sp3, sp4)
I want to know, how can I stagger this points to be represented as in the left side of the figure below? Alternately, I'm trying to also plot pie charts on those points where the size of PIE reflects the overall abundance. I don't even know if this is possible in R..but I'm shooting my shot here. Any help would be welcome!
If you want to use a dodged position, set position = position_dodge()
and specify a width:
library(ggplot2)
ggplot(df.long, aes(x = lat, y = long, color = species, size = abundance)) +
geom_point(position = position_dodge(width = 0.5))