0
votes

I am making a line plot and would like to plot the average with confidence interval in shades next to it. I can plot the data just as line plot, but that doesn't work quite well because the data is scattered way to much.

Data looks like this:

     subsidy_to_port tick industry_cost_to_store
1                20    7                1900000
2                20    8                2800000
3                20    9                3700000
4                20   10                4600000
5                20   11                5500000
6                20   12                6400000
7                20   13                7300000
8                20   14               10300000
9                20   15               13300000
10               20   16               16300000

The subsidy to port goes from 0 to 100 % in steps of 20, I want that factored to show 5 different graphs in one figure. The ticks go from 0 to 32, and the industry_cost_to_store gradually goes up. I tried this for the normal plot:

StoredCO215mln <- ggplot(i3, aes(x = tick, y =           
total_co2_emissions_captured)) + geom_point(aes(color =    
factor(subsidy_to_port))) + ylab("Amount CO2 captured") + labs(title   
= "Total CO2 captured in 32 years (subsidy = 15mln)") + 
scale_color_discrete(name="Subsidy to port (%)")

Choosing points gives a lot of scattered points, geom_line just does not work for this data. As you can see, the data set is called i3. I looked at the geom_ribbon command but cannot figure out how this works. All help appreciated! Thanks a lot.

Max

2
Is geom_smooth what you’re after? It sounds like it is.Konrad Rudolph

2 Answers

1
votes

From your description, the following should be what you want:

StoredCO215mln <- ggplot(i3) +
    aes(x = tick, y = total_co2_emissions_captured, color = factor(subsidy_to_port)) +
    geom_smooth(method = loess) +
    labs(title = "Total CO2 captured in 32 years (subsidy = 15mln)", y = "Amount CO2 captured") + 
    scale_color_discrete(name = "Subsidy to port (%)")

Since you mentioned “average line” I’ve used LOESS regression but you might want to play around with this and try others, e.g. simple linear regression.

1
votes

Is it something like that you want ?

ggplot(mpg, aes(displ, hwy)) + geom_point() +
  geom_smooth(method = "lm", formula = y ~ 1)

enter image description here