我有两个不同年份的鱼的饮食比例数据。我正在努力让气泡大小反映出可能的值的范围是从0到1,但没有一个值真正达到1。这是我在SigmaPlot中制作的一个图,我想在R中重新创建。有12种不同的猎物类别。

我已经设法在R中创建了一个图,但大小似乎缩放到了最大的比例。这是代码和复制的图。
library(reshape)
library(ggplot2)
Species <- as.character(c(1:12))
yr2016 <- as.numeric(c(0.17, 0.011, 0.022, 0.003, 0.51, 0.1,
0.01, 0.03, 0.004, 0.06, 0.07, 0.01))
yr2017 <- as.numeric(c(0.197, 0.005, 0.027, 0.01, 0.337, 0.157,
0.008, 0.038, 0.017, 0.17, 0.032, 0.002))
data <- as.data.frame(cbind(Species, yr2016, yr2017))
data$yr2016 <- as.numeric(as.character(data$yr2016))
data$yr2017 <- as.numeric(as.character(data$yr2017))
data2 <- melt(data)
ggplot(data2,
aes(x = variable, y = factor(Species, levels = unique(Species))))+
geom_point(aes(size = value))+
labs(y = "Prey Items", x = "Year")+
theme_classic() +
scale_size_area()

发布于 2019-02-12 05:18:38
您可以使用参数limits = c(0,1)在scale_size_area中手动设置限制,并使用max_size参数手动设置最大区域的大小,即max_size = 20
希望这能让你得到你想要的东西。
library(reshape)
library(ggplot2)
library(data.table)
Species <- as.character(c(1:12))
yr2016 <-as.numeric(c(0.17,0.011,0.022,0.003,0.51,0.1,0.01,0.03,0.004,0.06,0.07,0.01))
yr2017 <-as.numeric(c(0.197,0.005,0.027,0.01,0.337,0.157,0.008,0.038,0.017,0.17,0.032,0.002))
data<-as.data.frame(cbind(Species,yr2016,yr2017))
data$yr2016 <- as.numeric(as.character(data$yr2016));
data$yr2017 <- as.numeric(as.character(data$yr2017))
data2<-melt(data)
p <- ggplot2::ggplot(data2,aes(x=variable, y=factor(Species, levels=unique(Species))))+
geom_point(aes(size=value))+
labs(y="Prey Items",x="Year")+
theme_classic() +
scale_size_area( limits = c(0,1),max_size = 20)
p

如果需要,您还可以添加自己的breaks,如c(0.1, 0.2, 0.5, etc)或创建一系列中断:seq(from = 0.1, to = max(data2$value), by = 0.1)
如果您不仅想设置最大值,还想设置最小值,您可以切换到scale_size而不是scale_size_area,其中range(min,max)设置刻度两端的大小
library(reshape)
library(ggplot2)
library(data.table)
Species <- as.character(c(1:12))
yr2016 <-as.numeric(c(0.17,0.011,0.022,0.003,0.51,0.1,0.01,0.03,0.004,0.06,0.07,0.01))
yr2017 <-as.numeric(c(0.197,0.005,0.027,0.01,0.337,0.157,0.008,0.038,0.017,0.17,0.032,0.002))
data<-as.data.frame(cbind(Species,yr2016,yr2017))
data$yr2016 <- as.numeric(as.character(data$yr2016));
data$yr2017 <- as.numeric(as.character(data$yr2017))
data2<-melt(data, id = 'Species')
sizes <- c('0.2' = 0.2, '0.4' = 0.4, '0.6' = 0.6, '0.8'= 0.8, '1.0' = 1.0)
p <- ggplot2::ggplot(data2,aes(x=variable, y=factor(Species, levels=unique(Species))))+
geom_point(aes(size=value))+
labs(y="Prey Items",x="Year")+
theme_classic() +
scale_size( limits = c(0,1),breaks = seq(from = 0.1, to = max(data2$value), by = 0.1),range = c(1,20))
p

https://stackoverflow.com/questions/54638898
复制相似问题