我已使用其中的代码来创建我的图例的范围:R ggplot2 - geom_point custom color ranges and colors
dput很大,所以我放在这里dput of break_year_map_data_nona
这是我正在使用的代码
break_year_map_data_nona %>%
ggplot(aes(long, lat, group = group, fill = cut(value, c(1961, 1980, 1990, 2000, 2010, 2016)))) +
geom_polygon() +
coord_map(xlim=c(-180,180)) +
theme_void() +
labs(title = "", fill = "Break year")
但是传说得到了科学的记号:
我试图从这里遵循提示How to change scientific notation on legend labels in ggplot2
由于我有离散数据,因此尝试了以下代码:
break_year_map_data_nona %>%
ggplot(aes(long, lat, group = group, fill = cut(value, c(1961, 1980, 1990, 2000, 2010, 2016)))) +
geom_polygon() +
scale_fill_discrete(labels = comma) +
coord_map(xlim=c(-180,180)) +
theme_void() +
labs(title = "", fill = "Break year")
但是我收到了错误消息(我也尝试了连续操作,但也无法正常工作)
Error in UseMethod("round_any") :
no applicable method for 'round_any' applied to an object of class "character"
我该怎么做才能使它正常工作?
break_year_map_data_nona %>%
mutate(
break_year = cut(value, breaks = c(1961, 1980, 1990, 2000, 2010, 2016),
labels = c("1960-", "1980-", "1990-", "2000-", "2010-2016"))
)
ggplot(aes(long, lat, group = group, fill = break_year )) +
geom_polygon() +
coord_map(xlim=c(-180,180)) +
theme_void() +
labs(title = "", fill = "Break year")