R可视化小本本

R|可视化|Real2Integers

2021-02-27  本文已影响0人  高大石头

在ggplot2绘图中,x、y轴连续变量的分割位置(breaks)和预期的不一致,这时候就需要我们去进行细微的调整。

核心函数:

示例数据

rm(list = ls())
library(tidyverse)
library(palmerpenguins)
theme_set(theme_bw(16))

penguins %>% 
  ggplot(aes(bill_length_mm,bill_depth_mm,color=species))+
  geom_point()
image.png

调整坐标轴

penguins %>% 
  ggplot(aes(bill_length_mm,bill_depth_mm,color=species))+
  geom_point()+
  scale_y_continuous(breaks = seq(14,22,by=2))+
  scale_x_continuous(breaks = seq(30,60,by=5))
image.png

Session Info

sessionInfo()
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=Chinese (Simplified)_China.936 
## [2] LC_CTYPE=Chinese (Simplified)_China.936   
## [3] LC_MONETARY=Chinese (Simplified)_China.936
## [4] LC_NUMERIC=C                              
## [5] LC_TIME=Chinese (Simplified)_China.936    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] palmerpenguins_0.1.0 forcats_0.5.0        stringr_1.4.0       
##  [4] dplyr_1.0.2          purrr_0.3.4          readr_1.4.0         
##  [7] tidyr_1.1.2          tibble_3.0.4         ggplot2_3.3.2       
## [10] tidyverse_1.3.0     
## 
## loaded via a namespace (and not attached):
##  [1] prettydoc_0.4.0   tidyselect_1.1.0  xfun_0.19         haven_2.3.1      
##  [5] colorspace_2.0-0  vctrs_0.3.5       generics_0.1.0    htmltools_0.5.0  
##  [9] yaml_2.2.1        rlang_0.4.9       pillar_1.4.7      glue_1.4.2       
## [13] withr_2.3.0       DBI_1.1.0         dbplyr_2.0.0      modelr_0.1.8     
## [17] readxl_1.3.1      lifecycle_0.2.0   munsell_0.5.0     gtable_0.3.0     
## [21] cellranger_1.1.0  rvest_0.3.6       evaluate_0.14     labeling_0.4.2   
## [25] knitr_1.30        fansi_0.4.1       broom_0.7.2       Rcpp_1.0.5       
## [29] scales_1.1.1      backports_1.2.0   jsonlite_1.7.1    farver_2.0.3     
## [33] fs_1.5.0          hms_0.5.3         digest_0.6.27     stringi_1.5.3    
## [37] grid_4.0.3        cli_2.2.0         tools_4.0.3       magrittr_2.0.1   
## [41] crayon_1.3.4      pkgconfig_2.0.3   ellipsis_0.3.1    xml2_1.3.2       
## [45] reprex_0.3.0      lubridate_1.7.9.2 assertthat_0.2.1  rmarkdown_2.5    
## [49] httr_1.4.2        rstudioapi_0.13   R6_2.5.0          compiler_4.0.3

参考链接:

https://datavizpyr.com/change-x-and-y-axis-values-to-integers-ggplot2/

上一篇 下一篇

猜你喜欢

热点阅读