修改刻度朝內(nèi)
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'), #設(shè)置y軸的刻度長(zhǎng)度為負(fù)數(shù),即向內(nèi)
axis.text.y = element_text(margin = unit(c(0.5, 0.5, 0.5, 0.5), 'cm'))) #設(shè)置y軸標(biāo)簽距離y軸的距離

image.png
稍微美化
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'))

image.png
修改y軸刻度朝內(nèi),設(shè)置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軸刻度朝內(nèi)
theme(axis.line = element_line(arrow = arrow(length = unit(0.5, 'cm')))) #坐標(biāo)軸尾端為箭頭

image.png