我试图在基本条形图中绘制2个变量。
我有一个赔率和结束位置列表。我试图通过完成位置来计算赔率。
Odds Finish Position
5 6
6 5
3 3
4 2
2 4
1.8 1
到目前为止,我已尝试过以下内容:
ggplot(data.combined, aes(x = Odds)) + geom_bar(aes(fill = finish_pos))
但它显示为一条很小的线。我怎么调整?我的数据大约有1000行。
答案 0 :(得分:3)
使用geom_line
?
require(ggplot2);
ggplot(df, aes(x = Finish_Position, y = Odds)) + geom_line();
或使用geom_bar
?
ggplot(df, aes(x = Finish_Position, y = Odds)) + geom_bar(stat = "identity");
# Sample data
df <- read.table(text =
"Odds Finish_Position
5 6
6 5
3 3
4 2
2 4
1.8 1", header = T)
str(data.combined)
导致:
$ row_id : Factor w/ 1132 levels "2017-03-04_Flemington_9_ Gunn Island_False",..: 10 3 7 5 2 4 6 8 9 1 ...
$ entry_id : Factor w/ 100 levels "2017-03-04_9_False",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Odds : num 38 10 3.95 7.2 12.5 4 42 65 7.8 60 ...
$ BP : int 1 1 1 1 1 0 1 1 0 1 ...
$ offset : logi NA NA NA NA NA NA ...
$ horse_win : int 0 0 0 0 0 0 0 0 1 0 ...
$ horse_wp : int 0 1 0 0 0 1 1 0 1 0 ...
$ min_races : int 1 1 1 1 1 1 1 1 1 1 ...
$ days_since : int 1 1 0 0 0 0 0 0 1 1 ...
$ last_race_res : int 0 0 1 0 0 0 0 1 1 0 ...
$ last_race_wp : int 0 1 1 0 0 1 1 1 1 1 ...
$ last_three_races: int 0 1 1 0 0 1 1 1 1 0 ...
$ horse_dist_win : int 0 0 1 0 1 0 0 0 0 0 ...
$ horse_dist_wp : int 0 1 1 0 0 1 1 0 0 0 ...
$ horse_track_win : int 0 1 0 0 0 0 0 0 0 0 ...
$ horse_track_wp : int 0 1 0 0 0 1 1 0 0 0 ...
$ horse_going_win : int 0 1 0 0 0 0 0 1 1 0 ...
$ horse_going_wp : int 0 1 0 0 0 1 1 0 1 0 ...
$ finish_pos : int 6 9 2 5 8 1 4 3 7 10 ...
summary(data.combined$Odds) results in:
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.47 8.00 17.00 39.93 40.00 910.00