I have a dataframe which I would like to create a bargraph with primary and secondary axes.
geom_bar(data=top_ten_S, aes(x=Combination, y=AvgTopline), stat="identity",fill="red") +
coord_flip() +
geom_text(
data=top_ten_S,
aes(
x=Combination, y=AvgTopline,
label=paste0("R",round(AvgTopline,0)),
hjust=ifelse(AvgTopline < max(top_ten_S$AvgTopline) / 1.5, -0.1, 1.1), # <- Here lies the magic
),
)
my df looks like
top_ten_S <- data.frame(Combination = c("a", "b", "c"),
Nrcustomers = c(20, 200, 1900),
AvgTopline = c(1000,3000,1500))
I am only able to plot one column with the above code - I would like to a secondary axes so that I could plot Combination against NrCustomers and AvgTopline in