我正在使用boxplot
创建一个ggplot
,一切正常,直到我使用geom_text
向水平线添加标签。
这是我在没有geom_text
的情况下使用的代码以及相应的输出:
ggplot(data = x_frame, aes(x = '', y = x_frame)) +
scale_y_log10(labels = comma, name='Transaction (GBP)') +
geom_boxplot() +
ggtitle('Box & Whisker')+
geom_hline(aes(yintercept = SE, colour = 'Tukey'), linetype='dashed') +
geom_hline(aes(yintercept = mean(x),colour = 'Mean'),linetype='dashed') +
geom_hline(aes(yintercept = mean_std,colour = 'Mean & 1Std'),linetype='dashed')+
scale_colour_manual(name = 'Thresholds', values=c(Tukey='red', Mean='blue', 'Mean & 1Std'='darkred'))+
guides(colour = guide_legend(override.aes = list(shape = c('Tukey','Mean','Mean & 1Std'), size = 3)))
以下是使用geom_text
和输出后的代码:
ggplot(data = x_frame, aes(x = '', y = x_frame)) +
scale_y_log10(labels = comma, name='Transaction (GBP)') +
geom_boxplot() +
ggtitle('Box & Whisker')+
geom_hline(aes(yintercept = SE, colour = 'Tukey'), linetype='dashed') +
geom_hline(aes(yintercept = mean(x),colour = 'Mean'),linetype='dashed') +
geom_hline(aes(yintercept = mean_std,colour = 'Mean & 1Std'),linetype='dashed')+
scale_colour_manual(name = 'Thresholds', values=c(Tukey='red', Mean='blue', 'Mean & 1Std'='darkred'))+
geom_text(aes(y=SE, label=prettyNum(round(SE),big.mark=","), x=0.1), colour='red', hjust=-0.1 , vjust = 1) +
geom_text(aes(y=mean(x), label=prettyNum(round(mean(x)),big.mark=","), x=0.1), colour='blue', hjust=-0.1 , vjust = -0.5 ) +
geom_text(aes(y=mean_std, label=prettyNum(round(mean_std),big.mark=","), x=0.1), colour='darkred', hjust=-0.1 , vjust = -0.5) +
guides(colour = guide_legend(override.aes = list(shape = c('Tukey','Mean','Mean & 1Std'), size = 3)))
对不起,我不能发布数据,但只是它是一个高标准偏差的数字向量(因此,为什么我使用日志转换)。
非常感谢