hour_mark avg_intensity
<int> <dbl>
0 2.1295503
1 1.4190782
2 1.0439443
3 0.4437299
4 0.6330472
5 4.9506438
6 7.7712137
7 10.7336198
8 14.6680988
9 15.3877551
10 17.6437029
11 16.9212513
12 19.8470716
13 18.7752443
14 18.8686211
15 15.5846995
16 17.7166483
17 21.6556291
18 21.9216336
19 21.3852097
20 14.3399558
21 12.0729282
22 9.0630531
23 4.9966777
ggplot(data=avg_int_hourly,
aes(x=hour_mark,
y=avg_intensity,group=1))
geom_line(color="red")
geom_point()
scale_x_discrete(labels=hour_mark)
labs(title='Average Intensity Each Hour of the Day')
xlab('Hours of Day')
ylab('Average Intensity')
我想在 x 軸上表示一天中的所有 24 小時,所以我嘗試使用定義的 x (hour_mark) scale_x_discrete 和 scale_x_continuous 但 R 找不到物件:
Error in check_breaks_labels(breaks, labels): object 'hour_mark' not found
Traceback:
1. scale_x_discrete(labels = hour_mark)
2. discrete_scale(c("x", "xmin", "xmax", "xend"), "position_d",
. identity, ..., expand = expand, guide = guide, position = position,
. super = ScaleDiscretePosition)
3. check_breaks_labels(breaks, labels)
請幫忙!
uj5u.com熱心網友回復:
兩件事情:
scale_x_discrete需要一個離散值,您已經提供了一個帶有數字列的連續值。我們可以使用factor. (請注意,雖然這在下面有效,但如果資料沒有以類似數字的方式排序,那么我們的呼叫factor可能需要使用factor(., levels=).)scale_*函式不會像geom_*函式一樣進行非標準評估,需要傳遞明確的向量/物件。從技術上講,我們在這里不需要這個,但我會包括一個可以做更多控制的事情(注釋掉)。
ggplot(data=avg_int_hourly,
aes(x=factor(hour_mark),
y=avg_intensity,group=1))
geom_line(color="red")
geom_point()
## don't really need this, since the default action for discrete is
## to show all of them on the axis
# scale_x_discrete(breaks=avg_int_hourly$hour_mark, labels=avg_int_hourly$hour_mark)
labs(title='Average Intensity Each Hour of the Day')
xlab('Hours of Day')
ylab('Average Intensity')

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/478902.html
上一篇:我應該如何在我的.htaccess檔案中撰寫這些重寫規則
下一篇:R:在彼此的頂部繪制點列
