【问题标题】:How to get rid of degree symbols on the axis text in ggplot?如何摆脱ggplot中轴文本上的度数符号?
【发布时间】:2020-06-03 02:04:14
【问题描述】:

我有一张使用 ggplot 创建的地图。 x 和 y 轴上的文本是经度和纬度值。当我将数据框中的值添加到地图时,它们旁边有度数符号,但我想去掉度数符号。我只想要轴标题中的度数符号。我的地图是这样的。

下面是我用来导入地图和绘制数据的代码。我已经指定了这些度数符号的来源

canada = map_data("worldHires", "Canada")

ggplot(data = canada) +
  geom_polygon(data = canada, aes(x=long, y = lat, group = group), fill = "grey") +
  coord_sf(xlim=c(-64.5,-62.8), ylim=c(42.7,45), expand = FALSE) +
  labs(x=expression(paste("Longitude ",degree,"W",sep="")),
       y=expression(paste("Latitude ",degree,"N",sep=""))) +

  #Here is where the degree symbols are added
  geom_point(data = mapindividual_dets,
             mapping = aes(x = longitude, 
                           y = latitude),
             size = 10) 

这是我拥有的数据框示例,它给我带来了问题。我不能把它全部放在这里,因为它太大了。

mapindividual_dets = structure(list(location = c("ARB-04", "BIRCHY HEAD", "Boca1", 
                                                 "BON-AR-S2", "BON-AR-S2", "BON-W-S5"), month = structure(c(12L, 
                                                                                                            10L, 10L, 8L, 11L, 2L), .Label = c("Jan", "Feb", "Mar", "Apr", 
                                                                                                                                               "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = c("ordered", 
                                                                                                                                                                                                                  "factor")), year = c(2018, 2018, 2018, 2018, 2018, 2018), animal_id = c("NSTR-007", 
                                                                                                                                                                                                                                                                                          "NSTR-007", "NSTR-021", "NSTR-007", "NSTR-007", "NSTR-007"), 
                                    detection_count = c(3L, 256L, 2L, 4L, 2L, 2L), num_unique_tags = c(1L, 
                                                                                                       1L, 1L, 1L, 1L, 1L), total_res_time_in_seconds = c(0, 1182040, 
                                                                                                                                                          0, 2732221, 0, 0), latitude = c(24.94808, 44.5713, 26.32559, 
                                                                                                                                                                                          -49.27732, -49.27732, -49.27985), longitude = c(-80.45412, 
                                                                                                                                                                                                                                          -64.03512, -80.07108, 69.48038, 69.48038, 69.47853)), class = c("grouped_df", 
                                                                                                                                                                                                                                                                                                          "tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L), groups = structure(list(
                                                                                                                                                                                                                                                                                                            location = c("ARB-04", "BIRCHY HEAD", "Boca1", "BON-AR-S2", 
                                                                                                                                                                                                                                                                                                                         "BON-AR-S2", "BON-W-S5"), month = structure(c(12L, 10L, 10L, 
                                                                                                                                                                                                                                                                                                                                                                       8L, 11L, 2L), .Label = c("Jan", "Feb", "Mar", "Apr", "May", 
                                                                                                                                                                                                                                                                                                                                                                                                "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = c("ordered", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                            "factor")), year = c(2018, 2018, 2018, 2018, 2018, 2018), 
                                                                                                                                                                                                                                                                                                            .rows = list(1L, 2L, 3L, 4L, 5L, 6L)), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                 -6L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))

有人知道如何去掉坐标轴文本上的度数符号吗?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    提供您自己的标签。你可以使用一个函数。我推荐I,如果你想保留这个标志(例如,西度被编码为负数)或abs,如果你不想要这个标志。

    nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
    ggplot(nc) +
        geom_sf(aes(fill = AREA)) +
        scale_x_continuous(label = abs) +
        scale_y_continuous(label = abs)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 2017-01-24
      相关资源
      最近更新 更多