Matt
Matt

Reputation: 81

Basic bar chart

I am trying to plot 2 variables in a basic bar chart.

I have a list of odds and finishing position. I am trying to chart odds by finishing position.

Odds    Finish Position
5       6 
6       5
3       3
4       2
2       4
1.8     1

So far I have tried the following:

ggplot(data.combined, aes(x = Odds)) + geom_bar(aes(fill = finish_pos))

But it shows as one very small line. How can I adjust? My data has about 1000 rows.

Upvotes: 0

Views: 91

Answers (1)

Maurits Evers
Maurits Evers

Reputation: 50668

Something like this using geom_line?

require(ggplot2);
ggplot(df, aes(x = Finish_Position, y = Odds)) + geom_line();

enter image description here

Or using geom_bar?

ggplot(df, aes(x = Finish_Position, y = Odds)) + geom_bar(stat = "identity");

enter image description here


Sample data

# 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) results in:

$ 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

Upvotes: 3

Related Questions