0

I would like to add a trend line over to see the trend over the various quarters when divided by the geographical locations. This is the plot to which I would like to add the trendline.

Quart <- c("Q1", "Q2", "Q3", "Q4", "Q1", "Q2", "Q3", "Q4" )
Locate <- c("US", "Other", "US", "US", "Other", "US", "US", "Other")
Product_Price <- c(10, 25, 36, 153, 23, 20, 96, 785)
Product_ID <- c("helme[enter image description here][1]t", "gloves", "jacket", "helmet", "jacket", "glasses", "hoody", "gloves")
df <- data.frame (Quart, Locate, Product_ID, Product_Price)
df$Quart <- as.factor(df$Quart)
df$Locate <- as.factor(df$Locate)

#Price data Over Quarters by Location
library(ggplot2)
ggplot(df, aes(x = df$Quart, y = df$Product_Price, fill = Locate)) +
        geom_bar(stat="identity", position=position_dodge()) +
        labs(x = "Quarter", y="Product Price", title = "Price over Quarter and Location") +
        scale_fill_hue(name="Product Type") +
        facet_wrap(~Locate)
jakub
  • 4,774
  • 4
  • 29
  • 46
D Petrova
  • 91
  • 1
  • 6
  • I don't think so - this plot is a bar chart, while the suspect duplicate is a scatterplot (or at least it mentions points), so this one may be asking for something slightly different. – jakub Oct 07 '16 at 08:46
  • On that note: What exactly do you want your line to be like? Should y coordinates of its points be the same as the height of individual bars? – jakub Oct 07 '16 at 08:57
  • Yes, I would like the trend line to be showing the difference from the highest value of the bar or it could be showing the difference between the average for the different quarters, located in each facet. – D Petrova Oct 07 '16 at 09:08
  • Do you want `geom_smooth(aes(x = as.numeric(Quart)), method = "lm", se = F)` ? – cuttlefish44 Oct 07 '16 at 09:13
  • Yes, I think so! Would you also be able to help me get the line that shows the trend of the average. – D Petrova Oct 07 '16 at 09:21
  • 2
    `geom_smooth(aes(x = as.numeric(Quart)), method = "lm", formula = y ~ 1, se = F)` – cuttlefish44 Oct 07 '16 at 09:33
  • Cool, thank you cuttlefish! – D Petrova Oct 07 '16 at 09:58

0 Answers0