修改刻度朝内
library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = drv, shape = drv)) +
theme_bw() +
theme(axis.ticks.length.y = unit(-0.15, 'cm'), #设置y轴的刻度长度为负数,即向内
axis.text.y = element_text(margin = unit(c(0.5, 0.5, 0.5, 0.5), 'cm'))) #设置y轴标签距离y轴的距离
稍微美化
ggplot(mpg, aes(displ, hwy)) +
geom_point(aes(color = drv, shape = drv)) +
labs(title = 'Engine Displacement VS. Highway Miles per Gallon',
color = 'Type of Drives',
shape = 'Type of Drives') +
theme_bw() +
theme(axis.ticks.length.y = unit(-0.15, 'cm'),
axis.text.y = element_text(margin = unit(c(0.5, 0.5, 0.5, 0.5), 'cm'))) +
theme(plot.title = element_text(hjust = 0.5, face = 4, color = 'darkred', size = rel(1.5)),
legend.title = element_text(face = 2),
axis.title = element_text(face = 'bold')) +
scale_shape_discrete(breaks = c('4', 'f', 'r'),
labels = c('Four-Wheel Drive', 'Front-Wheel Drive', 'Rear- Wheel Drive')) +
scale_color_discrete(breaks = c('4', 'f', 'r'),
labels = c('Four-Wheel Drive', 'Front-Wheel Drive', 'Rear- Wheel Drive'))
修改y轴刻度朝内,设置xy轴尾部为箭头
ggplot(mpg, aes(x = hwy)) +
geom_histogram(bins = 15) +
theme_classic() +
theme(axis.ticks.length.y = unit(-0.15, 'cm'),
axis.text.y = element_text(margin = unit(c(0.5, 0.5, 0.5, 0.5), 'cm'))) + #修改y轴刻度朝内
theme(axis.line = element_line(arrow = arrow(length = unit(0.5, 'cm')))) #坐标轴尾端为箭头