无论如何,我们可以增加图例图标与其文字之间的距离。例如,在下面的例子中,我想将图例标签“A”,“B”移动到远离矩形图例键的位置(参考预期图)
library(ggplot2)
######################
#create simple dataframe for plotting
xy <- data.frame(x=1:10, y=10:1, type = rep(LETTERS[1:2], each=5))
xy
#create base plot
p <- ggplot(data = xy)+
geom_bar(data=xy, aes(x=x, y=y, fill=type), stat="identity")
#plot base plot
p
#legend text
p + theme(legend.text = element_text(colour = 'red', size = 10, hjust = 1, vjust = 1, face = 'bold'))