Given the data below. This code will generate a dataframe of the data used in the plot
Assuming the sample data in the code reflects your actual data, the bars would have heights corresponding to the variance values (300, -250, 400, and 200) for each region. The text labels on top of the bars would show the corresponding percentage variances (23.1%, -14.3%, 36.4%, and 9.8%).
<code>df <- tibble(
Region = c("North", "South", "East", "West"),
Budget = c(1300, 1750, 1100, 2050),
Actual = c(1600, 1500, 1500, 2250),
Variance = c(1600 - 1300, 1500 - 1750, 1500 - 1100, 2250 - 2050),
Base_Variance = c(1300, 1500, 1100, 2050),
Positive_Variance = c(ifelse(1600 > 1300, 1600 - 1300, ""),
ifelse(1500 > 1750, 1500 - 1750, ""),
ifelse(1500 > 1100, 1500 - 1100, ""),
ifelse(2250 > 2050, 2250 - 2050, "")),
Negative_Variance = c(ifelse(1600 < 1300, 1300 - 1600, ""),
ifelse(1500 < 1750, 1750 - 1500, ""),
ifelse(1500 < 1100, 1100 - 1500, ""),
ifelse(2250 < 2050, 2050 - 2250, "")),
Variance_Percent = c(paste0(round((1600 - 1300) / 1300 * 100, 1), "%"),
paste0(round((1500 - 1750) / 1750 * 100, 1), "%"),
paste0(round((1500 - 1100) / 1100 * 100, 1), "%"),
paste0(round((2250 - 2050) / 2050 * 100, 1), "%"))
)
# Print the data frame
print(df)
</code>
<code>df <- tibble(
Region = c("North", "South", "East", "West"),
Budget = c(1300, 1750, 1100, 2050),
Actual = c(1600, 1500, 1500, 2250),
Variance = c(1600 - 1300, 1500 - 1750, 1500 - 1100, 2250 - 2050),
Base_Variance = c(1300, 1500, 1100, 2050),
Positive_Variance = c(ifelse(1600 > 1300, 1600 - 1300, ""),
ifelse(1500 > 1750, 1500 - 1750, ""),
ifelse(1500 > 1100, 1500 - 1100, ""),
ifelse(2250 > 2050, 2250 - 2050, "")),
Negative_Variance = c(ifelse(1600 < 1300, 1300 - 1600, ""),
ifelse(1500 < 1750, 1750 - 1500, ""),
ifelse(1500 < 1100, 1100 - 1500, ""),
ifelse(2250 < 2050, 2050 - 2250, "")),
Variance_Percent = c(paste0(round((1600 - 1300) / 1300 * 100, 1), "%"),
paste0(round((1500 - 1750) / 1750 * 100, 1), "%"),
paste0(round((1500 - 1100) / 1100 * 100, 1), "%"),
paste0(round((2250 - 2050) / 2050 * 100, 1), "%"))
)
# Print the data frame
print(df)
</code>
df <- tibble(
Region = c("North", "South", "East", "West"),
Budget = c(1300, 1750, 1100, 2050),
Actual = c(1600, 1500, 1500, 2250),
Variance = c(1600 - 1300, 1500 - 1750, 1500 - 1100, 2250 - 2050),
Base_Variance = c(1300, 1500, 1100, 2050),
Positive_Variance = c(ifelse(1600 > 1300, 1600 - 1300, ""),
ifelse(1500 > 1750, 1500 - 1750, ""),
ifelse(1500 > 1100, 1500 - 1100, ""),
ifelse(2250 > 2050, 2250 - 2050, "")),
Negative_Variance = c(ifelse(1600 < 1300, 1300 - 1600, ""),
ifelse(1500 < 1750, 1750 - 1500, ""),
ifelse(1500 < 1100, 1100 - 1500, ""),
ifelse(2250 < 2050, 2050 - 2250, "")),
Variance_Percent = c(paste0(round((1600 - 1300) / 1300 * 100, 1), "%"),
paste0(round((1500 - 1750) / 1750 * 100, 1), "%"),
paste0(round((1500 - 1100) / 1100 * 100, 1), "%"),
paste0(round((2250 - 2050) / 2050 * 100, 1), "%"))
)
# Print the data frame
print(df)
Create this plot in R
New contributor
user5706932 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.