Вы можете установить пределы вручную внутри scale_size_area
с аргументом limits = c(0,1)
и вручную установить размер самой большой области с аргументом 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
, где диапазон (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