如何在ggplot2中的图之间保持点大小比例不变?

use*_*288 2 r point scale ggplot2

我制作了一系列人口分布图的GIF(使用ggplot2和Image Magick),其中每个样本都有个体数量以及纬度和经度值。但是,每个图的值范围不同,因此图之间的大小是恒定的。我正在尝试在图形之间保持值的大小不变(即,低于该点的值为30,则该点的大小将大于该图之前的值为10的大小)。

这是一个可重现的示例:

    #simulating latitude and longitude point creation
    a <- c("1","1")
    b <- c("2","2")
    c <- c("3","1")

    x <- rbind(a,b,c)
    x <- as.data.frame(x)

    #simulating the total individual count in my data
    mag1 <- as.numeric(c("2", "6", "10"))
    mag2 <- as.numeric(c("2", "6", "30"))

    d1 <- cbind(x, mag1)
    d2 <- cbind(x, mag2)

    #Plotting the two scatter plots
    g1 <- ggplot(data=d1, aes(x=V1, y=V2)) + geom_point(aes(size=mag1))
    g1
    g2 <- ggplot(data=d2, aes(x=V1, y=V2)) + geom_point(aes(size=mag2))
    g2
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏!(如果代码混乱,或者我的问题没有100%清楚地传达,我是R的新手,请提前道歉!)

Did*_*rts 5

对所有图使用scale_size_continuous()并设置相同的limits=值。通过参数,breaks=您可以设置将在图例中获得的值(中断)。如果在绘图上获得的最大点太小,则还可以更改range=默认值为的参数range=c(1,6)

g1 + scale_size_continuous(limits=c(1,30),breaks=c(5,10,20,30))

g2 + scale_size_continuous(limits=c(1,30),breaks=c(5,10,20,30))
Run Code Online (Sandbox Code Playgroud)