ggplot轴使用coord_polar标记掉图形

时间:2019-02-27 19:59:34

标签: r ggplot2

我有一个极坐标的图形,我希望宽约6英寸,长约2.5英寸,但是,尽管尝试了各种测量方法,但我仍无法获得显示所有x轴标签(尤其是270)的图像值。

enter image description here

我尝试在主题(axis.text.x = ...)中使用“调整”和“调整”,但这似乎并没有改变标签的位置。我还想尝试仅删除x轴的刻度线(y很有用),但这似乎也无济于事。

ggplot(data = df),
       aes(bear, distKM, colour = yday(date))) + 
  geom_segment(aes(xend = bear, yend = 10)) + 
  geom_point(shape = 1) +
  coord_polar(start = pi) +
  scale_color_gradientn(colours = c("grey80", "grey60", "grey40", "black"), 
                        limits = c(min(yday(df$date)), max(yday(df$date))),
                        breaks = c(196, 212, 227),
                        labels = c("15 Jul", "1 Aug", "15 Aug")) +
  scale_x_continuous(limits = c(-180, 180),
                     breaks =  c(-180, -90, 0, 90),
                     labels = c("180", "270", "0", "90")) +
  scale_y_log10() +
  facet_grid(~bear.type, 
             labeller = labeller(bear.type = c("first" = "First detection", 
                                               "last" = "Last detection"))) +
  labs(y = "Distance (km)",
       x = "", 
       colour = "Departure date") +
  guides(colour = guide_colourbar(reverse = T)) +
  geom_hline(yintercept = c(100, 1000), colour = "grey90", size = 0.2) +
  geom_vline(xintercept = seq(-180, 180, by = 45), colour = "grey90", size = 0.2) +


    theme_bw() + 
  theme(axis.text = element_text(size = 9, colour = "black"),
        axis.text.x = element_text(margin=unit(c(0, 0, 0, 0), "cm")),
        axis.title = element_text(size = 10, colour = "black"),
        legend.text = element_text(size = 9, colour = "black"),
        legend.title = element_text(size = 9, colour = "black"),
        panel.grid  = element_blank(),
        strip.text = element_text(size = 9, colour = "black"),
        strip.background = element_rect(colour = "white",
                                        fill = "white"))

编辑(02/27/19) -提供的数据

dput(df)
structure(list(bear = c(-113.055484753995, -113.055484753995, 
    -117.775313897586, -113.055484753995, -117.775313897586, 5.13040414326106, 
    -113.055484753995, -113.055484753995, -178.019796767721, -118.947139553976, 
    -117.824638356611, -159.028166230323, -159.028166230323, -116.017935839186, 
    -117.824638356611, -159.028166230323, -118.096575564792, -118.382553464738, 
    -118.096575564792, 6.29798915295773, -121.896598385887, -116.017935839186, 
    -122.929838388751, -120.156297610393, -127.981467072544, -119.70781349504, 
    -121.06432368251, -106.097798358436, 17.8804094556518, 91.05638140673, 
    -113.055484753995, -113.055484753995, -118.902296595238, -113.055484753995, 
    -121.597818010344, 5.13040414326106, -113.055484753995, -113.055484753995, 
    -118.902296595238, -118.947139553976, -127.296214563736, -126.89837910689, 
    -159.028166230323, -125.275715048877, -118.258141664608, -124.370971534491, 
    -118.096575564792, -118.096575564792, -118.096575564792, -121.789656442143, 
    -126.88376142202, -117.150692547485, -122.929838388751, -120.156297610393, 
    -127.981467072544, -119.70781349504, -119.70781349504, -105.572359788796, 
    -11.1255985273144, -121.599492037066), bear.type = c("first", 
    "first", "first", "first", "first", "first", "first", "first", 
    "first", "first", "first", "first", "first", "first", "first", 
    "first", "first", "first", "first", "first", "first", "first", 
    "first", "first", "first", "first", "first", "first", "first", 
    "first", "last", "last", "last", "last", "last", "last", "last", 
    "last", "last", "last", "last", "last", "last", "last", "last", 
    "last", "last", "last", "last", "last", "last", "last", "last", 
    "last", "last", "last", "last", "last", "last", "last"), distKM = c(19.1707182324242, 
    19.1707182324242, 568.509667010717, 19.1707182324242, 568.509667010717, 
    37.0774308692358, 19.1707182324242, 19.1707182324242, 84.2698843789311, 
    604.702826072703, 569.234909503913, 24.3966666034348, 24.3966666034348, 
    740.870514316907, 569.234909503913, 24.3966666034348, 768.228256642873, 
    289.713044260461, 768.228256642873, 37.9341659344014, 15.752024224683, 
    740.870514316907, 1103.26890588624, 15.0031347313238, 1169.79390843064, 
    68.6782663984571, 66.0167024818575, 1036.71172353881, 25.9413197245392, 
    40.6034606007984, 19.1707182324242, 19.1707182324242, 603.967369524483, 
    19.1707182324242, 620.976660240894, 37.0774308692358, 19.1707182324242, 
    19.1707182324242, 603.967369524483, 604.702826072703, 1093.65294869467, 
    820.292118509268, 24.3966666034348, 1175.93637999388, 574.863070835869, 
    61.6508990041585, 768.228256642873, 768.228256642873, 768.228256642873, 
    622.474461457948, 32.3204808456489, 757.003815065291, 1103.26890588624, 
    15.0031347313238, 1169.79390843064, 68.6782663984571, 68.6782663984571, 
    1030.6288930804, 38.7546560909801, 620.981814104136), date = structure(c(1406297348.1112, 
    1407276094.4158, 1406330632.0613, 1407490305.4993, 1406552025.8514, 
    1405964739.2527, 1407078925.0925, 1406285074.475, 1406123078.5834, 
    1438097832.985, 1438097743.3089, 1438252727.6824, 1436190169.4567, 
    1437577437.0105, 1438209133.1853, 1438794640.5246, 1438173337.2322, 
    1438083434.1402, 1438251288.8178, 1437844819.4679, 1438247033.9429, 
    1438171703.2655, 1534507807.6186, 1533820579.7317, 1534093849.7991, 
    1533041446.3001, 1534086023.11, 1532882823.5637, 1531824345.5634, 
    1533568517.8915, 1406297348.1112, 1407276094.4158, 1406330632.0613, 
    1407490305.4993, 1406552025.8514, 1405964739.2527, 1407078925.0925, 
    1406285074.475, 1406123078.5834, 1438097832.985, 1438097743.3089, 
    1438252727.6824, 1436190169.4567, 1437577437.0105, 1438209133.1853, 
    1438794640.5246, 1438173337.2322, 1438083434.1402, 1438251288.8178, 
    1437844819.4679, 1438247033.9429, 1438171703.2655, 1534507807.6186, 
    1533820579.7317, 1534093849.7991, 1533041446.3001, 1534086023.11, 
    1532882823.5637, 1531824345.5634, 1533568517.8915), class = c("POSIXct", 
    "POSIXt"), tzone = "UTC")), class = c("tbl_df", "tbl", "data.frame"
    ), row.names = c(NA, -60L))

0 个答案:

没有答案