當我繪制條形圖時,圖表在 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"))
uj5u.com熱心網友回復:
ocean_whole在您將其交給.tibble之前,您的 tibble 包含多個值ggplot()。這些值的總和等于意外值。查看:
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))
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358893.html
