簡體   English   中英

R和ggplot2:如何連接折線圖和極坐標的點?

[英]R and ggplot2: how do I connect the dots for a line chart and polar coordinates?

可見

正如我的同事指出的那樣,連接點是他們在小學教學的東西。

這是數據:

hour_timetable  mean_delayed_pass
0   6.074
1   6.512
2   7.632
3   9.393
4   8.759
5   4.600
6   6.040
7   5.575
8   5.680
9   6.315
10  6.895
11  7.852
12  6.832
13  6.961
14  6.322
15  5.954
16  5.579
17  5.540
18  5.142
19  5.579
20  6.139
21  6.501
22  6.140
23  6.061

這是代碼:

library(ggplot2)
ggplot(data = test_vis, aes(x = factor(hour_timetable), y = mean_delayed_pass, group = 1)) + 
   ylim(0, NA) + 
   geom_point(color = 'purple', stat = 'identity') + 
   geom_line(color = 'purple') + 
   coord_polar(start = -0.12) # why offset?

使用geom_polygon()而不是geom_line() 您可以使用geom_polygon(..., fill=NA)為多邊形設置空填充。

嘗試這個:

library(ggplot2)
ggplot(data = test_vis, aes(x = factor(hour_timetable), y = mean_delayed_pass, group = 1)) + 
  ylim(0, NA) + 
  geom_point(color = 'purple', stat = 'identity') + 
  geom_polygon(color = 'purple', fill=NA) + 
  coord_polar(start = - pi * 1/24)

在此輸入圖像描述


要將零點放在圖的頂部,請使用offset = - pi / 24

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM