R語(yǔ)言ggplot2修改y軸標(biāo)簽朝內(nèi)、箭頭坐標(biāo)軸

修改刻度朝內(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容