0

Question:

I am trying to plot a demand curve based on quantity and cost data. The problem is that when plotting the data, I get an upward slopping curve (Figure 1); whereas I am interested in a downward slopping curve to reflect demand behavior. I kind of manage to generate the plot by having negative values for the x-axis (Figure 2), however that is not optimal since I want to plot on the same plot a supply curve.

Data:

Data

Code:

    # Load Data
    df = tbl_df(read_excel("BeWhere_BiomassDemand.xlsx", sheet = "PlotDat", col_names = TRUE))

    # Add variables
    df.fin = ddply(df, .(Operation,Feedstock), transform, wSupply = cumsum(Supply), wDemand = cumsum(Demand))
    df.fin = mutate(df.fin, wmSupply = wSupply - Supply,
                    wtSupply = wmSupply + (wSupply - wmSupply)/2,
                    wmDemand = wDemand - Demand,
                    wtDemand = wmDemand + (wDemand - wmDemand)/2)

    pDem = ggplot(df.fin, aes(ymin = 0))
    pDem = pDem + geom_rect(aes(xmin = -wmDemand, xmax = -wDemand, ymax = Cost, fill = Feedstock), alpha = 0.35)
    pDem = pDem + geom_line(aes(x = -wDemand, y = Cost, group = Feedstock, color = Feedstock), size = 1)
    pDem = pDem + scale_fill_brewer(palette = "PuOr")
    pDem = pDem + scale_color_brewer(palette = "PuOr")
    pDem = pDem + labs(title = "Forest-based feedstock demand curves in Sweden",
                       x = "Demand (in TWh/year)",
                       y = "Cost (in MEUR/year)")
    pDem = pDem + facet_grid(. ~ Operation, scales = "free") + theme_bw()
    pDem = pDem + theme(plot.title = element_text(size = rel(2), face = "bold", hjust = 0.5, vjust = 1),
                axis.title.x = element_text(size = rel(1.6), hjust = 0.5, vjust = 0),
                axis.title.y = element_text(size = rel(1.6), hjust = 0.5, vjust = 1),
                axis.text.x = element_text(size = rel(1.85), hjust = 0.5, vjust = 0.5),
                axis.text.y = element_text(size = rel(1.85), hjust = 0.5, vjust = 0.5),
                legend.title = element_text(size = rel(1.5)),
                legend.text = element_text(size = rel(1.5)),
                strip.text = element_text(size = rel(1.5), face = "bold"))
    pDem = pDem + scale_y_continuous(breaks = seq(0,40,5))
    pDem

Figure 1:Figure 1 Figure 2:Figure 2

iouraich
  • 2,944
  • 5
  • 29
  • 40
  • If you could use dput() to make reproducible code it would be helpful instead of linking to the data separately. – Docconcoct Nov 10 '15 at 12:43
  • 1
    I don't know what you are doing here. If your curve slopes upward, that is it. You can't really change it without (drastically) rescaling your data (which is what you did). Are these really demand curves (which are quite difficult to measure as they are based in fiction), or are they measured prices and consumptions for various years (which is what they look like). – Mike Wise Nov 10 '15 at 13:30
  • You could try: `+ scale_x_continuous(trans = "reverse", breaks = unique(df$wmDemand))` or try `scale_x_reverse()`. See here for a similar solution: http://stackoverflow.com/a/28392170/2653210 – Docconcoct Nov 10 '15 at 13:31
  • @MikeWise The data represents estimated harvest cost and demand for forest feedstock at the gridcell level. The curves are a cumulative sum across all gridcells, which technically amount to a rough estimate of how much demand is there for forest feedstock given the cost. – iouraich Nov 10 '15 at 14:31
  • @Docconcoct I will try your way and see what I get. – iouraich Nov 10 '15 at 14:31
  • So you have a demand curve that slopes upwards with cost? This is very rare and normally only true for status goods in certain markets. But surely these are commodities? – Mike Wise Nov 10 '15 at 14:34
  • @MikeWise Well, technically not. The demand I am plotting is an output from a model that takes data on forest feedstock availability (supply) and harvest cost - taken as an approximate of market price for forest feedstock - to optimize biorefineries plant location, and as an output we get the demand data that I am trying to plot. From an economic perspective, the demand for feedstock from a plant should be negatively related to the cost data. – iouraich Nov 11 '15 at 08:01
  • So they are technically not commodities? Or technically the demand curve does not have a positive slope? Not trying to be difficult, just trying to follow you here. – Mike Wise Nov 11 '15 at 08:25
  • @iouraich any luck with my suggestion? – Docconcoct Nov 12 '15 at 16:55
  • 1
    @Docconcoct It worked with `scale_x_reverse()` and it generates the right picture for the curves. However, the x-axis is displayed from 60 to 0 as it should after using the reverse option. But it is misleading because the plot would be interpreted: as market price (approximated with cost) increases, demand increases as well which is counter to economic intuition. – iouraich Nov 12 '15 at 18:31

0 Answers0