如何从此图例ggplot中删除科学符号

问题描述 投票:0回答:1

我已使用其中的代码来创建我的图例的范围: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")

但是传说得到了科学的记号:

Map with scientific notation

我试图从这里遵循提示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"

我该怎么做才能使它正常工作?

r ggplot2 scientific-notation
1个回答
0
投票
我无法获取您的数据,并尝试执行此操作以查看其是否有效:

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")

© www.soinside.com 2019 - 2024. All rights reserved.