简体   繁体   English

带有 R 的气泡图

[英]Bubble chart with R

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.我想制作一个气泡图,其中 y 轴代表物种丰度,x 轴代表月份,而气泡半径代表我在该月发现的物种丰度。

My data arrangement is like this我的数据排列是这样的

在此处输入图片说明

I want to end up the bubble chart with like this我想像这样结束气泡图

乐

Please help me.请帮我。 Thank you谢谢

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 .请参阅从宽格式到长格式重塑 data.frame 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])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM