Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何使用几何图形条(ggplot2)垂直居中标签_R_Ggplot2_Center_Geom Bar - Fatal编程技术网

R 如何使用几何图形条(ggplot2)垂直居中标签

R 如何使用几何图形条(ggplot2)垂直居中标签,r,ggplot2,center,geom-bar,R,Ggplot2,Center,Geom Bar,我将非常感谢对ggplot2的一些帮助。我似乎无法垂直居中的酒吧标签 代码如下: library(ggplot2) Group.id <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3) Type.id <- c("a", "b", "c", "d", "a", "b", "c", "d","a", "b", "c", "d") Value <- c(4000, 3200, 9529, 3984, 7504, 1244, 8960, 1865, 1

我将非常感谢对ggplot2的一些帮助。我似乎无法垂直居中的酒吧标签

代码如下:

library(ggplot2)

Group.id <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
Type.id <- c("a", "b", "c", "d", "a", "b", "c", "d","a", "b", "c", "d")
Value <- c(4000, 3200, 9529, 3984, 7504, 1244, 8960, 1865, 1100, 1100, 0, 0)
df <- data.frame(Group.id, Type.id, Value)


ggplot(df, aes(x = Group.id, y = Value, label = Value)) +
  geom_bar(stat = "identity", aes(fill = Type.id)) +
  scale_fill_manual(values=c("#00AF50", "#64A70B", "#F2A900", "#C30C3E"), labels = rev(unique(df$Type.id))) +
  geom_text(position = position_stack(vjust = .5), color = "#FFFFFF") 
库(ggplot2)

Group.idPut
fill=Type.id
在第一个
aes()调用中:

ggplot(df, aes(x = Group.id, y = Value, label = Value, fill = Type.id)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values=c("#00AF50", "#64A70B", "#F2A900", "#C30C3E"), labels = rev(unique(df$Type.id))) +
  geom_text(position = position_stack(vjust = .5), color = "#FFFFFF")