Following is my data
df <- data.frame(Lab = c("Queen II", "MMH", "Berea", "Maluti", "Motebang"),
Expected = c(13200, 5280, 5280, 2640, 5280),
Actual = c(8759, 761, 2263, 2210, 6100),
utili_pct = c(66.35, 14.41, 42.86, 83.71, 115.53))
and I have tried to plot a bar chat which includes a line over the chart.
step 1
# I Converted numeric variable "Actual" to a factor
df$Actualx <- as.factor(df$Actual)
This was so that I could plot a chart with two-factor variables vs one numeric So I tidy the data and ran the plot this way but the axis scale became no ordered.
tidy_Data = df %>% gather(key, value, Actualx, Expected)
ggplot(tidy_Data, aes(x=Lab, y=value, fill=key)) +
geom_bar(stat = "identity", position = position_dodge(0.8)) `
Futhermore,
I tried to add a line utili_ptc
and the second axis, but the scale is giving me a hard time,
The line does not align with the bars.
ggplot(tidy_Data, aes(x=Lab, y=value, fill=key)) +
geom_bar(stat = "identity", position = position_dodge(0.8)) +
geom_line(aes(x=Lab, y=utili_pct), color = "green", group = 1)