[R] How to manually color specific bars
Jeff Reichman
re|chm@nj @end|ng |rom @bcg|ob@|@net
Wed Aug 22 04:23:06 CEST 2018
Please disregard I simply added a highlight variable and added
scale_fill_manual(values = c("Yes"="red", "No"="grey"))
-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Jeff Reichman
Sent: Tuesday, August 21, 2018 8:44 PM
To: r-help using r-project.org
Subject: [R] How to manually color specific bars
R-Help Forum
While the following code works fine I need to change (highlight) specific
"bars" within plot 2 (p2). For example I want the bars to be (lets say)
red, on 1 Aug 2016 and 1 Aug 2017 . What do I need to do?
library(ggplot2)
library(reshape2)
library(scales)
library(egg)
#data <- dataset
data <- read.csv("~/R/Data_Files/AreaPlotData.csv", stringsAsFactors=FALSE)
data$Serial <- seq.int(nrow(data))
data$min <- pmin(data$Melbourne,data$Sydney)
data <- melt(data, id.vars=c("Serial","min","Timeline"), value.name="Price")
data$Timeline <- as.Date(data$Timeline, format="%m/%d/%Y")
p1 <- ggplot(data, aes(x = Timeline, y = Price)) +
geom_line(aes(col = variable)) + geom_ribbon(aes(ymin = min, ymax = Price,
fill = variable), alpha = 0.3) +
scale_color_manual(values = c("#144A90","#D81F26")) +
scale_fill_manual(values = c("#F7A396","#88CADD")) +
theme_get() + theme(legend.position="top", legend.title=element_blank()) +
scale_x_date(labels=date_format("%b%y"))
data2 <- read.csv("~/R/Data_Files/AreaPlotData2.csv",
stringsAsFactors=FALSE)
data2$Timeline <- as.Date(data2$Timeline, format="%m/%d/%Y")
p2 <- ggplot(data2, aes(x = Timeline, y=Port)) +
geom_bar(stat = "identity", width = 0.1, color = "blue") +
scale_y_continuous(name="Port Holdings", limits=c(0, 40))
ggarrange(p1, p2, heights = c(2, 0.6),ncol = 1, nrow = 2)
Jeff
[[alternative HTML version deleted]]
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list