r-可以让ggplot2条形图显示Y轴的直接值吗



当我绘制条形图时,图表在Y轴上显示了我不理解的值。如何使条形图使用实际值?

#Here is the code for my graph
stock %>%
#Tidy data to be handled correctly
group_by(year) %>%
filter(year == "2017") %>%
pivot_longer(bio_sus:bio_notsus) %>%
mutate(value2 = ifelse(name=="bio_sus",-1*value, value)) %>%
#make the graph
ggplot(aes(ocean_whole, value2/100, fill=name)) +
geom_bar(stat = "identity")

当我的值2的值在100到-100 之间时,条形图显示的值在2.5到-2.5之间

ocean_sub                   code   year ocean_whole   name       value value2
<chr>                       <chr> <dbl> <chr>         <chr>      <dbl>  <dbl>
1 Eastern Central Atlantic    NA     2017 atlantic      bio_sus     57.1  -57.1
2 Eastern Central Atlantic    NA     2017 atlantic      bio_notsus  42.9   42.9
3 Eastern Central Pacific     NA     2017 pacific       bio_sus     86.7  -86.7
4 Eastern Central Pacific     NA     2017 pacific       bio_notsus  13.3   13.3
5 Eastern Indian Ocean        NA     2017 indian        bio_sus     68.6  -68.6

如何使图表显示实际值?

#My code is from TidyTuesdays Global seafood:
stock <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-12/fish-stocks-within-sustainable-levels.csv')
#transformed in the following way
oceans <- c("pacific", "atlantic", "indian", "mediterranean")
lu <- stack(sapply(oceans, grep, x = stock$entity, ignore.case = TRUE))
stock$oceans <-  stock$entity
stock$oceans[lu$values] <- as.character(lu$ind)
stock %>%
group_by(oceans) %>%
summarise(across(matches("^share"), sum))
colnames(stock) <- (c("ocean_sub", "code", "year", "bio_sus", "bio_notsus", "ocean_whole"))

在将tibble交给ggplot()之前,它包含ocean_whole的多个值。这些值的总和构成意外值。检查:

library(dplyr)
stock %>%
group_by(year) %>%
filter(year == "2017") %>%
pivot_longer(bio_sus:bio_notsus) %>%
mutate(value2 = ifelse(name=="bio_sus",-1*value, value)) %>%
group_by(ocean_whole, name) %>%
summarise(sum(value2))

最新更新