I am a beginner to R so I apologise in advance if this is a very basic question.
I am plotting a box plot showing the type of bars and their various quantities in 1990 and 2010. I have two problems here:
- I wish to remove the years of 1980, 2000, 2020. I tried using
scale_x_discrete("1990","2010")
but it doesn't seem to work. - The legend at the bottom lists the names of the bars. However, i wish to replace the
.
with spaces. For example, changingmid.channel.bar
toMid-channel bar
.
library(ggplot2)
library(tidyr)
library(reshape2)
barCount <- tibble::tribble(
~Year, ~Lateral.bar, ~Bar.accreted.to.island, ~Mid.channel.bar,
1990, 105, 134, 62,
2010, 102, 189, 102
)
df2 <- melt(barCount, id="Year")
barPlot <- ggplot(df2, aes(Year,value)) +
geom_bar(aes(fill=variable),position="dodge",stat="identity") +
labs(y="Quantity",fill="")+
scale_fill_manual("Legend",values=c("Lateral.bar"="khaki4","Bar.accreted.to.island"="Khaki2",
"Mid.channel.bar"="ivory"))
#modifying axis
barPlot <- barPlot + theme(
axis.title.x = element_blank(),
axis.title.y = element_text(size=14),
axis.text.x = element_text(size=14),
legend.position="bottom"
)
barPlot