r - geom_sf : scale_*_continuous has no effect

标签 r ggplot2 r-sf

以下将 scale_x_continuousgeom_sf 结合使用可完全删除 x 轴标签。 我假设指定的中断实际上并不存在于 ggplot 对象中,因此根本不会显示任何中断。

这是由coord_sf()自动从EPSG 32717转换为EPSG 4326引起的吗?

data(ecuador, package = "sperrorest")
library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2
library(ggplot2)
data = st_as_sf(ecuador, coords = c("x", "y"), crs = 32717)
ggplot(data) + 
  geom_sf()

ggplot(data) + 
  geom_sf() + 
  scale_x_continuous(breaks = c(79.085, 79.055))

devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.3 (2017-11-30)
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       Europe/Berlin               
#>  date     2018-01-29
#> Packages -----------------------------------------------------------------
#>  package    * version    date       source                            
#>  backports    1.1.2      2017-12-13 CRAN (R 3.4.3)                    
#>  base       * 3.4.3      2017-12-01 local                             
#>  class        7.3-14     2015-08-30 CRAN (R 3.4.0)                    
#>  classInt     0.1-24     2017-04-16 CRAN (R 3.4.3)                    
#>  colorspace   1.3-2      2016-12-14 CRAN (R 3.4.3)                    
#>  compiler     3.4.3      2017-12-01 local                             
#>  datasets   * 3.4.3      2017-12-01 local                             
#>  DBI          0.7        2017-06-18 CRAN (R 3.4.3)                    
#>  devtools     1.13.4     2017-11-09 CRAN (R 3.4.3)                    
#>  digest       0.6.15     2018-01-28 cran (@0.6.15)                    
#>  e1071        1.6-8      2017-02-02 CRAN (R 3.4.3)                    
#>  evaluate     0.10.1     2017-06-24 CRAN (R 3.4.3)                    
#>  ggplot2    * 2.2.1.9000 2018-01-29 Github (tidyverse/ggplot2@401511e)
#>  graphics   * 3.4.3      2017-12-01 local                             
#>  grDevices  * 3.4.3      2017-12-01 local                             
#>  grid         3.4.3      2017-12-01 local                             
#>  gtable       0.2.0      2016-02-26 CRAN (R 3.4.3)                    
#>  htmltools    0.3.6      2017-04-28 CRAN (R 3.4.3)                    
#>  knitr        1.19       2018-01-29 cran (@1.19)                      
#>  lazyeval     0.2.1      2017-10-29 CRAN (R 3.4.3)                    
#>  magrittr     1.5        2014-11-22 CRAN (R 3.4.3)                    
#>  memoise      1.1.0      2017-04-21 CRAN (R 3.4.3)                    
#>  methods    * 3.4.3      2017-12-01 local                             
#>  munsell      0.4.3      2016-02-13 CRAN (R 3.4.3)                    
#>  pillar       1.1.0      2018-01-14 cran (@1.1.0)                     
#>  plyr         1.8.4      2016-06-08 CRAN (R 3.4.3)                    
#>  Rcpp         0.12.15    2018-01-20 cran (@0.12.15)                   
#>  rlang        0.1.6.9003 2018-01-29 Github (tidyverse/rlang@a8c15c6)  
#>  rmarkdown    1.8        2017-11-17 CRAN (R 3.4.3)                    
#>  rprojroot    1.3-2      2018-01-03 CRAN (R 3.4.3)                    
#>  scales       0.5.0.9000 2018-01-29 Github (hadley/scales@d767915)    
#>  sf         * 0.6-0      2018-01-06 CRAN (R 3.4.3)                    
#>  stats      * 3.4.3      2017-12-01 local                             
#>  stringi      1.1.6      2017-11-17 CRAN (R 3.4.3)                    
#>  stringr      1.2.0      2017-02-18 CRAN (R 3.4.3)                    
#>  tibble       1.4.2      2018-01-22 cran (@1.4.2)                     
#>  tools        3.4.3      2017-12-01 local                             
#>  udunits2     0.13       2016-11-17 CRAN (R 3.4.3)                    
#>  units        0.5-1      2018-01-08 CRAN (R 3.4.3)                    
#>  utils      * 3.4.3      2017-12-01 local                             
#>  withr        2.1.1.9000 2018-01-29 Github (jimhester/withr@df18523)  
#>  yaml         2.1.16     2017-12-12 CRAN (R 3.4.3)

最佳答案

您的休息时间必须为负数,因为您位于西半球:

ggplot(data) + 
    geom_sf() + 
    scale_x_continuous(breaks = c(-79.085, -79.055))

enter image description here

使用coord_sf直接从ggplot更改crs也很容易:

ggplot(data) + 
    geom_sf() + 
    coord_sf(datum = st_crs(data)) +
    scale_x_continuous(breaks = c(712500, 715500))

enter image description here

关于r - geom_sf : scale_*_continuous has no effect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48510238/

相关文章:

r - 如何在ggplot2中创建具有大量值的点图

返回 R 中 sf 对象的完整案例

r - 防止 spData::world 国家环绕 map /裁剪 map 区域

R 中的砖形图

r - 如何在 R Circlize 中添加轨道标签?

r - 使用 2 个变量的 facet_wrap 更改 strip.text 的颜色

r - ggplot2 段——x 轴为时间时的方向

r - 如何从人口普查形状文件(邮政编码级别)中删除所有小岛?

r - 为什么unsplit这么慢

r - 在 R markdown 中包装长 url 行