r抖动叠加条形图

r抖动叠加条形图,r,ggplot2,label,jitter,R,Ggplot2,Label,Jitter,我正在绘制一个堆叠的方框图来表示下面的数据 Choice Race Freq countT per <fct> <ord> <dbl> <dbl> <chr> 1 Pepsi Asian 362 20684 1.7501% 2 Coke Asian 363 20684 1.755% 3 Sprite Asian 204 20684 0.9863%

我正在绘制一个堆叠的方框图来表示下面的数据

  Choice   Race   Freq countT per     
   <fct>    <ord> <dbl>  <dbl> <chr>   
 1 Pepsi    Asian   362  20684 1.7501% 
 2 Coke     Asian   363  20684 1.755%  
 3 Sprite   Asian   204  20684 0.9863% 
 4 Gatorade Asian     1  20684 0.0048% 
 5 Pepsi    Black   150  20684 0.7252% 
 6 Coke     Black   408  20684 1.9725% 
 7 Sprite   Black   322  20684 1.5568% 
 8 Gatorade Black    45  20684 0.2176% 
 9 Pepsi    Other  1088  20684 5.2601% 
10 Coke     Other  2407  20684 11.637% 
11 Sprite   Other   223  20684 1.0781% 
12 Gatorade Other   113  20684 0.5463% 
13 Pepsi    White  2384  20684 11.5258%
14 Coke     White  5038  20684 24.357% 
15 Sprite   White  6882  20684 33.2721%
16 Gatorade White   694  20684 3.3553% 
选择比赛频率计数
1百事亚洲362 20684 1.7501%
2焦炭亚洲363 20684 1.755%
3雪碧亚洲204 20684 0.9863%
4佳得乐亚洲120684 0.0048%
5百事可乐150 20684 0.7252%
6焦黑408 20684 1.9725%
7雪碧黑32220684 1.5568%
8佳得乐黑45 20684 0.2176%
9百事可乐其他1088 20684 5.2601%
10焦炭其他2407 20684 11.637%
11雪碧其他223 20684 1.0781%
12佳得乐其他113 20684 0.5463%
13百事白2384 20684 11.5258%
14焦白5038 20684 24.357%
15雪碧白6882 20684 33.2721%
16佳得乐白色694 20684 3.3553%
下面是我的代码

library(ggplot2)

colortest <- c("#FBCF357F", "#ED4C1C7F", "#9C7E707F", "#5AC2F17F" )

ggplot(testdf, aes(x = Choice, y = Freq, fill = Race, label = Freq)) +
  geom_bar(stat = "identity") + 
  geom_text(size = 4, position = position_stack(vjust = 0.5)) +
  scale_fill_manual(values =  colortest) +
  scale_colour_manual(values = colortest) +
  coord_flip() +
  theme_bw() +
  ylab("Count by Race")
库(ggplot2)

颜色测试轻松奶酪搭配
ggrepel
:-)

代码
库(ggplot2)
图书馆(ggrepel)
颜色测试
library(ggplot2)
library(ggrepel)

colortest <- c("#FBCF357F", "#ED4C1C7F", "#9C7E707F", "#5AC2F17F" )

ggplot(df, aes(x = Choice, y = Freq, fill = Race, label = Freq)) +
  geom_bar(stat = "identity") + 
  # Here it is
  geom_text_repel(size = 4, position = position_stack(vjust = 0.5)) +
  scale_fill_manual(values =  colortest) +
  scale_colour_manual(values = colortest) +
  coord_flip() +
  theme_bw() +
  ylab("Count by Race")
df <- read.table(text = "Choice   Race   Freq countT per      
 Pepsi    Asian   362  20684 1.7501% 
 Coke     Asian   363  20684 1.755%  
 Sprite   Asian   204  20684 0.9863% 
 Gatorade Asian     1  20684 0.0048% 
 Pepsi    Black   150  20684 0.7252% 
 Coke     Black   408  20684 1.9725% 
 Sprite   Black   322  20684 1.5568% 
 Gatorade Black    45  20684 0.2176% 
 Pepsi    Other  1088  20684 5.2601% 
Coke     Other  2407  20684 11.637% 
Sprite   Other   223  20684 1.0781% 
Gatorade Other   113  20684 0.5463% 
Pepsi    White  2384  20684 11.5258%
Coke     White  5038  20684 24.357% 
Sprite   White  6882  20684 33.2721%
Gatorade White   694  20684 3.3553%", strip.white = TRUE, header = TRUE)