简体   繁体   English

在 ggplot 中,为什么我的标签没有放在正确的 position 中?

[英]In ggplot, why my labels are not palced in the right position?

this is my dataframe:这是我的 dataframe:

    mydf <- structure(list(NOME = c(1, 1, 1, 1, 1), PLAYER.POSITION = c("Lateral", 
"Lateral", "Lateral", "Lateral", "Lateral"), variables_bar = structure(5:1, .Label = c("ACCELERATIONS.Z6", 
"ACCELERATIONS.Z5", "ACCELERATIONS.Z4", "ACCELERATIONS.Z3", "ACCELERATIONS"
), class = "factor"), value = c(185L, 111L, 49L, 22L, 3L)), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))

This is my plot:这是我的 plot:

mydf %>% ggplot() + geom_col(aes(x = NOME, y = value, fill = variables_bar)) + geom_label(aes(x = NOME, y = value,label = value))

The labels should be on the top of each bar, but its not.标签应该在每个栏的顶部,但不是。

Any help?有什么帮助吗?

Here is one way we could do it:这是我们可以做到的一种方法:

library(tidyverse)

mydf %>% ggplot() + 
  geom_col(aes(x = NOME, y = value, fill = variables_bar)) + 
  geom_label(aes(x = NOME, y = value, label = value),size=5,
             position=position_stack(vjust=0.5))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM