我有以下内容
R
代码正在运行
RStudio
,输出也如下所示:
df2 %>%
ggplot(aes(
x = JANUARY,
y = value,
fill = JANUARY,
group = year
)) +
geom_col(
position = position_dodge(.65),
width = .5
) +
geom_text(aes(
y = value + max(value) * .03,
label = round(value * 100) %>% str_c('%')
),
position = position_dodge(.65)
) +
geom_text(aes(
y = y_pos,
label = str_remove(year, 'X')
),
color = 'white',
angle = 90,
fontface = 'bold',
position = position_dodge(0.65)
) +
scale_y_continuous(
breaks = seq(0, .9, .1),
labels = function(x) round(x * 100) %>% str_c('%')
) +
scale_fill_manual(values = c(
rgb(47, 85, 151, maxColorValue = 255),
rgb(84, 130, 53, maxColorValue = 255),
rgb(244, 177, 131, maxColorValue = 255),
rgb(112, 48, 160, maxColorValue = 255),
rgb(90, 48, 100, maxColorValue = 255)
)) +
theme(
plot.title = element_text(hjust = .5),
panel.background = element_blank(),
panel.grid.major.y = element_line(color = rgb(.9, .9, .9)),
axis.ticks = element_blank(),
legend.position = 'none'
) +
xlab('') +
ylab('') +
ggtitle('Month of JANUARY (as at 01 January)')
输出为:
如您所见,“d-final”下的值“0%”导致条形内的标签消失在
x-axis
.
我想去掉“0%”,把标签放回横条内的位置。如何修改代码以实现这一点?
数据(
df2
):
JANUARY year value y_pos
<fct> <chr> <dbl> <dbl>
1 D-150 X2016 0.26 0.12
2 D-90 X2016 0.49 0.21
3 D-60 X2016 0.63 0.265
4 D-30 X2016 0.73 0.325
5 D-Final X2016 0.81 0
6 D-150 X2017 0.28 0.12
7 D-90 X2017 0.5 0.21
8 D-60 X2017 0.64 0.265
9 D-30 X2017 0.77 0.325
10 D-Final X2017 0.82 0
11 D-150 X2018 0.33 0.12
12 D-90 X2018 0.51 0.21
13 D-60 X2018 0.62 0.265
14 D-30 X2018 0.77 0.325
15 D-Final X2018 0.78 0
16 D-150 X2019 0.24 0.12
17 D-90 X2019 0.42 0.21
18 D-60 X2019 0.53 0.265
19 D-30 X2019 0.65 0.325
20 D-Final X2019 0 0