参考自《R Graphics Cookbook》
此处的经典坐标轴就是,最常见的,仅在x、y轴上显示坐标轴,而不是ggplot2默认的不显示,也不是整个四圈都有边的那种。
library(ggplot2)
library(gcookbook)
#底图
hw_plot <- ggplot(heightweight, aes(x = ageYear, y = heightIn)) +
geom_point()
#要告诉ggplot2在x、y轴上有边,才会有边
hw_plot +
theme(axis.line = element_line(colour = "black"))
##如果使用了生成四圈有边的主题,那么就需要让四圈的边先没有,然后再指定轴上有边
#这逻辑,真tm绝了,这是画图呢,还是考逻辑呢?
hw_plot +
#使用bw主题
theme_bw() +
theme(panel.border = element_blank(),
axis.line = element_line(colour = "black"))
#边太粗,默认的两个轴的接口处不完整
hw_plot +
theme_bw() +
theme(
panel.border = element_blank(),
axis.line = element_line(colour = "black", size = 4)
)
#指定边缘的lineend = "square", 两个粗边的接口处就可以接起来
hw_plot +
theme_bw() +
theme(
panel.border = element_blank(),
axis.line = element_line(colour = "black", size = 4, lineend = "square")
)
总结:
你tm知道默认的不完整,你设计的时候倒是把完整的改成默认啊!
ggplot2逻辑常常很感人,我不要你觉得,我要我觉得!