ggplot2精細(xì)化調(diào)整坐標(biāo)軸
## 調(diào)整坐標(biāo)軸范圍
```{r}
p <- ggplot(mtcars, aes(wt, drat,col=cyl)) + geom_point()
p
p+xlim(0,20)
p + scale_x_continuous(limits = c(0,15))
```
## 坐標(biāo)軸標(biāo)簽
```{r}
p + xlab("這是 X 軸") + ylab("這是 Y 軸") + ggtitle("這是標(biāo)題") ?
p + labs(x = "這是 X 軸", y = "這是 Y 軸", title = "這是標(biāo)題") ?
#### 修改 X 軸標(biāo)簽的大小、字體、顏色、加粗、位置、角度
windowsFonts(wlbb = windowsFont("仿宋"))
p + xlab("這是 X 軸") + theme(axis.title.x = element_text(size = 15, family = 'wlbb', color = "red", face = "bold", vjust = 0.5, hjust = 0.5, angle = 45))
```
## 標(biāo)簽特殊字符
```{r}
p+scale_x_continuous(labels = scales::label_number(accuracy = 0.0001))
p+scale_x_continuous(labels = scales::label_number(accuracy = 0.0001,suffix = "wlbb"))
p+scale_x_continuous(labels = scales::label_number(accuracy = 0.0001,suffix = "\u00b0C"))
p+scale_x_continuous(labels = scales::label_number(accuracy = 1,suffix = "\u2764 五柳冰冰"))+
? theme(axis.text.x = element_text(angle = 45,color = "red"))
```
## 刻度間隔
```{r}
p + scale_x_continuous(breaks=seq(0, 20, 0.5))?? ## X 軸每隔 .5 個(gè)單位顯示一個(gè)刻度
```
## 刪去所有刻度標(biāo)簽
```{r}
p+theme(axis.text = element_blank())?? ## 刪去所有刻度標(biāo)簽
```
```{r}
p+theme(axis.ticks = element_blank())?? ## 刪去所有刻度線(xiàn)
```
## 日期型數(shù)據(jù)坐標(biāo)軸
```{r}
p <- pedquant::md_future('rb2310')[[1]] %>% ggplot(aes(date,close))+
? geom_line()
p
p+scale_x_date(breaks = '2 month',date_labels = "%y 年 %b")
```