Skip to content

Instantly share code, notes, and snippets.

@Myfanwy
Created February 21, 2017 22:37
Show Gist options
  • Save Myfanwy/6ce76fd5c4af2df991f02f6c5c12f2d4 to your computer and use it in GitHub Desktop.
Save Myfanwy/6ce76fd5c4af2df991f02f6c5c12f2d4 to your computer and use it in GitHub Desktop.
geom_bar axes puzzle
library(tidyverse)
tt <- structure(list(TagID = c(2051L, 2051L, 2052L, 2055L, 2055L, 2057L,
2057L, 2058L, 2058L, 2059L, 2059L, 2061L, 2062L, 2063L, 2063L,
2064L, 2064L, 2066L, 2066L, 2067L, 2067L, 2068L, 2069L, 2070L,
2070L, 2071L, 2072L, 2073L, 2074L, 2075L, 2075L, 2076L, 2076L,
2077L, 2117L, 2117L), ttime = structure(c(17.0865856481481, 17.0865856481481,
5.9287037037037, 14.2212037037037, 14.2212037037037, 5.84836805555556,
5.84836805555556, 14.3217361111111, 14.3217361111111, 11.6971759259259,
11.6971759259259, 3.96478009259259, 8.38928240740741, 8.59267361111111,
8.59267361111111, 11.6124652777778, 11.6124652777778, 8.30859953703704,
8.30859953703704, 8.5684375, 8.5684375, 8.33138888888889, 3.32209490740741,
6.04434027777778, 6.04434027777778, 6.17700231481481, 1.61231481481481,
2.95548611111111, 1.60939814814815, 12.6649537037037, 12.6649537037037,
13.2399768518519, 13.2399768518519, 3.92450231481481, 6.45460648148148,
6.45460648148148), units = "days", class = "difftime"), laststation = c("MAE",
"MAE", "Base_TD", "MAE", "MAE", "MAE", "MAE", "MAW", "MAW", "MAE",
"MAE", "Lisbon", "BCE", "MAW", "MAW", "MAW", "MAW", "MAE", "MAE",
"MAW", "MAW", "I80_1", "BCE", "MAE", "MAE", "Base_TD", "Rstr",
"BCE", "Rstr", "MAW", "MAW", "MAW", "MAW", "BCE", "MAE", "MAE"
), ttimen = c(17.0865856481481, 17.0865856481481, 5.9287037037037,
14.2212037037037, 14.2212037037037, 5.84836805555556, 5.84836805555556,
14.3217361111111, 14.3217361111111, 11.6971759259259, 11.6971759259259,
3.96478009259259, 8.38928240740741, 8.59267361111111, 8.59267361111111,
11.6124652777778, 11.6124652777778, 8.30859953703704, 8.30859953703704,
8.5684375, 8.5684375, 8.33138888888889, 3.32209490740741, 6.04434027777778,
6.04434027777778, 6.17700231481481, 1.61231481481481, 2.95548611111111,
1.60939814814815, 12.6649537037037, 12.6649537037037, 13.2399768518519,
13.2399768518519, 3.92450231481481, 6.45460648148148, 6.45460648148148
), Rkm = c(69.19, 69.19, 113.9, 69.19, 69.19, 69.19, 69.19, 68.87,
68.87, 69.19, 69.19, 135.4, 106.4, 68.87, 68.87, 68.87, 68.87,
69.19, 69.19, 68.87, 68.87, 146.4, 106.4, 69.19, 69.19, 113.9,
121.01, 106.4, 121.01, 68.87, 68.87, 68.87, 68.87, 106.4, 69.19,
69.19), rkmtraveled = c(90.11, 90.11, 45.4, 90.11, 90.11, 90.11,
90.11, 90.43, 90.43, 90.11, 90.11, 23.9, 52.9, 90.43, 90.43,
90.43, 90.43, 90.11, 90.11, 90.43, 90.43, 12.9, 52.9, 90.11,
90.11, 45.4, 38.29, 52.9, 38.29, 90.43, 90.43, 90.43, 90.43,
52.9, 90.11, 90.11), kmday = c(5.27372769818212, 5.27372769818212,
7.65766047165391, 6.33631314742592, 6.33631314742592, 15.4077170150742,
15.4077170150742, 6.31417862320773, 6.31417862320773, 7.70356884179863,
7.70356884179863, 6.02807707914303, 6.30566446938196, 10.5240818041856,
10.5240818041856, 7.78732145473465, 7.78732145473465, 10.8453897192083,
10.8453897192083, 10.5538495204056, 10.5538495204056, 1.54836128429967,
15.9236871535629, 14.9081613309053, 14.9081613309053, 7.34984344932386,
23.7484637914202, 17.8989167978571, 23.7915024595116, 7.14017612030867,
7.14017612030867, 6.83007236431473, 6.83007236431473, 13.4794161798058,
13.9605722298531, 13.9605722298531), groupid = c("yolo2012",
"yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012",
"yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012",
"yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012",
"yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012",
"yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012",
"yolo2012", "yolo2012", "yolo2012", "yolo2012", "yolo2012")), .Names = c("TagID",
"ttime", "laststation", "ttimen", "Rkm", "rkmtraveled", "kmday",
"groupid"), row.names = c(NA, -36L), class = c("tbl_df", "tbl",
"data.frame"))
p1 <- ggplot(tt, aes(x = laststation, y = kmday)) +
geom_bar(stat = 'identity', aes(fill = laststation), show.legend = FALSE)
p2 <- ggplot(tt, aes(x = laststation, y = kmday)) +
geom_bar(stat = 'identity',position = 'identity', aes(fill = laststation), show.legend = FALSE)
p1
p2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment