# see ?ggplot2::arrow
arrow <- arrow(length = unit(0.5, "cm"), ends = "last", type = "closed")
# -------------------------------------------------------------------------
# A reproducible dataset from ggplot2 (you can use your own data set)
base <- ggplot(economics, aes(date, psavert)) +
geom_blank() +
labs(x="Kg", y="%") +
theme_bw()
# -------------------------------------------------------------------------
# Add a theme layer removing boarder, grid lines and add the axes arrow
base_bg <- base + theme(
panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(arrow = arrow)
)
# -------------------------------------------------------------------------
# finally position the axis title up to the arrow
base_bg + theme(axis.title.y = element_text(hjust = 1, size = 14, face="bold", family = "TT Times New Roman"), axis.title.x = element_text( hjust = 1, size = 14, face = "bold", family="Serif"))
输出
更新-纠正Y轴上的%
#see the addition of angle = 360 on axis.title.y
base_bg + theme(axis.title.y = element_text(hjust = 1, size = 14, face="bold", family = "TT Times New Roman", angle = 360), axis.title.x = element_text( hjust = 1, size = 14, face = "bold", family="Serif"))
3条答案
按热度按时间cpjpxq1n1#
这对我很有效。
axis.title.y = element_text( hjust = .5)
和axis.title.x = element_text( hjust = .5)
为默认值,将hjust
更改为0
将使轴文本位于坐标点(0,0)。更新
要复制背景和箭头,可以执行以下操作:
输出
更新-纠正Y轴上的
%
输出-更正标签“%”
zyfwsgd62#
尝试:
其中1,2,3,4表示 * 下、左、上、右 * 边距的度量
8yparm6h3#
可以使用
hjust
沿着直线移动轴标签,最大值为1。