我正在尝试表示与随人口成比例增加规模的城市相对应的点/气泡。
尽管进行了几次尝试,但我总是遇到相同的错误(“离散值提供给连续刻度”),即使我的变量是数字变量也是如此。
https://github.com/Lulliter/r-ggplot-points-question
ggplot() +
geom_sf (data = Brazil_bound_sf,
aes(fill = NULL), alpha = .1,colour = "darkgrey",size = 0.3) +
geom_point(data = Brazil_cit_longlat, aes( x = lon, y = lat, size =
"2016"), fill = "red", color = "grey", alpha = .2) +
scale_size_continuous() +
coord_sf(crs = st_crs(Brazil_bound_sf), datum = NA) +
theme_void()
# Error: Discrete value supplied to continuous scale
谢谢!
答案 0 :(得分:1)
这对我有用(我只是用2016
替换了“ 2016”。这样,您是指数据框中的列而不是字符串“ 2016”:
ggplot() +
geom_sf (data = x,
aes(fill = NULL), alpha = .1,colour = "darkgrey",size = 0.3) +
geom_point(data = y, aes( x = lon, y = lat, size =
`2016`), fill = "red", color = "grey", alpha = .2) +
scale_size_continuous() +
sf::plot_sf(crs = st_crs(x), datum = NA)