问题
I have a table with an abundance of species in different months. I want to make a bubble chart wherein the y-axis for abundance species and x-axis for the month while the radius of the bubbles for the abundance of species that I found in the month.
My data arrangement is like this
I want to end up the bubble chart with like this
Please help me. Thank you
回答1:
The following is a bubble graph created with a mock data set. I have tried to show how to plot a data set with a structure like the data set in the question and, as usual, this sort of problem is a data reformating problem. See reshaping data.frame from wide to long format. In this case I had to first have the row names as a new column. Only then the data was reformated.
library(tidyverse)
library(ggplot2)
df1 %>%
rownames_to_column(var = "id") %>%
gather(key, Abundance, -id) %>%
ggplot(aes(key, id)) +
geom_point(aes(size = Abundance), colour = "red", fill = "red", shape = 21) +
labs(x = "", y = "") +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5))
Data creation code.
set.seed(1234)
df1 <- matrix(0, nrow = 10, ncol = 5)
df1[sample(prod(dim(df1)), 10)] <- sample(200:250, 10)
df1 <- as.data.frame(df1)
dimnames(df1) <- list(letters[1:10], LETTERS[1:5])
来源:https://stackoverflow.com/questions/60025301/bubble-chart-with-r