我正在尝试为尺寸美学编辑图例,并为该美学设置比例尺尺寸,但似乎不能同时做到。
以下是步骤:
#create the map
library(ggplot2)
world <- broders("world")
#generate a dataframe of geolocated data with attributes
points <- data.frame(lat = seq(0, 50, 10),
lon = seq(0, 50, 10),
type = c("y", "n", "y", "n", "y", "n"),
impact.x.r = seq(0, 50, 10))
points
lat lon type impact.x.r
1 0 0 y 0
2 10 10 n 10
3 20 20 y 20
4 30 30 n 30
5 40 40 y 40
6 50 50 n 50
然后我在ggplot中映射点-一切正常:
ggplot() +
world +
geom_point(data = points, aes(x = lon, y = lat, col = type, size = impact.x.r)) +
scale_color_discrete(name = "types of birds", breaks = c("n","y"), labels = c("no", "yes")) +
scale_size_continuous(name = "impact")
但是,一旦我尝试使用+ scale_size()
设置比例尺大小,就会出现错误。我也失去了为尺寸美学传奇制作的格式:
ggplot() +
world +
geom_point(data = points, aes(x = lon, y = lat, col = type, size = impact.x.r)) +
scale_color_discrete(name = "types of birds", breaks = c("n","y"), labels = c("no", "yes")) +
scale_size_continuous(name = "impact") +
scale_size(range = c(0,15))
Scale for 'size' is already present. Adding another scale for 'size', which
will replace the existing scale.
如果我切换了scale_size_continuous()
和scale_size()
的呼叫顺序,我仍然会收到错误消息。这样一来,我就可以保留格式,但会丢失缩放比例的大小:
ggplot() +
world +
geom_point(data = points, aes(x = lon, y = lat, col = type, size = impact.x.r)) +
scale_color_discrete(name = "types of birds", breaks = c("n","y"), labels = c("no", "yes")) +
scale_size(range = c(0,15)) +
scale_size_continuous(name = "impact")
Scale for 'size' is already present. Adding another scale for 'size', which
will replace the existing scale.
因此它使用了对scale_size的最后一次调用...
但是我该如何修改图例以增加尺寸美感,并将scale_size设置为适合我的地图的尺寸?