After successfully running my bar plot, I have a PROBLEM where the numbers on the y axis are in codes and not in full, and instead of showing normal figures, it shows codes like 0e 00.
I would like the Y axis to show between 102,000 and 106,000.
The bar plot also has different figures. But it is not showing clearly the difference in yearly sales.
# Table of average total sales by year
yearly_sales <- DataSet %>% group_by(Year) %>% summarise(sales = mean(Weekly_Sales))
summarise(yearly_sales)
mycols <- c("#FF7F50", "#DE3163", "#6495ED")
# Bar chart for Average Yearly Sales 2010 to 2012
barplot(height = yearly_sales$sales, names = yearly_sales$Year, col = mycols)
How can I get the chart to show clearly the difference in sales and how can I get the actual values too instead of 0e 00
CodePudding user response:
This can be done using ylim
and xpd
, though I caution representing your data this way as it exaggerates the true difference between years and is a general violation of data visualization. The figure you represented in your question is more accurate.
At any rate, if you wanted to do this:
# Example data
data <- c(1033660, 1046239, 1059670)
# Plot, `a` saves the position of the x axis to place years text
a <- barplot(data, ylim = c(1020000, 1060000), xpd = FALSE, col = c("#FF7F50", "#DE3163", "#6495ED"))
axis(1, at = a, labels = c(2010, 2011, 2012), tick = FALSE)
ylim
sets the limits and xpd
clips the overhang at the lower axis.
CodePudding user response:
Data:
Yearly_sales <- structure(list(sales = c(1033660, 1046239, 1059670), Year = 2012:2010,
diff = c(-0.0245453773344532, -0.0126747006143422, 0)), class = "data.frame", row.names = c(NA,
-3L))