2
$\begingroup$

I have got Demand, Temperature, and Price data. I would like to plot Demand against other two variables separately to see the linear relationship between them, but the I that I got is very ugly. I am wondering is there any other plot that I can use? contour plot?

Thanks.

par(mfrow=c(1,2))
plot(data$Temp,data$Demand,ylab="Demand (MW)",
 xlab="Temperature (Celsius)",main = "Plot of Demand against Temperature")
abline(lm(data$Demand~data$Temp), col="red") 

plot(data$Price,data$Demand,ylab="Demand (MW)",
 xlab="Price (GBP)",main = "Plot of Demand against Price")
abline(lm(data$Demand~data$Price), col="red") 

enter image description here

$\endgroup$
7
  • $\begingroup$ First I would plot price against temperature. It looks like highest demands occurred at low temperatures, but simultaneously you have a strong relationship with price. Thus, I suspect that price and demand both depend on temperature. Also, it's not obvious to me if price or demand should be treated as the dependent variable here. Typically, both depend on each other. $\endgroup$
    – Roland
    Aug 26, 2016 at 9:20
  • 2
    $\begingroup$ People put on heating when it's cold but air conditioning when it's hot. Conversely, when it's warmer sometimes the heating is still on but people open windows when they can. Others have found elbows in the (demand, temperature) relationship. You may get nicer graphs with smaller point symbols and a grey colour, but above all think about applying any reasonable smoother (e.g. lowess/loess/locfit, local polynomials, splines) to check for nonlinearity in the data. $\endgroup$
    – Nick Cox
    Aug 26, 2016 at 9:32
  • $\begingroup$ In fact nonlinearity is easy to guess even from the crude scatter plot. The straight line is a very poor summary for high temperatures. At a wild guess these are average daily temperatures, but it's the maximum daily temperatures that are likely to be closer to relevant. $\endgroup$
    – Nick Cox
    Aug 26, 2016 at 10:19
  • $\begingroup$ @NickCox Thanks. The data is average hourly temperature. In term of nonlinearity, is it something like: $ Demand=\beta_0 +\beta_1 * Temp + \beta_2 * Temp^2... $? $\endgroup$
    – Jeannie
    Aug 26, 2016 at 11:51
  • $\begingroup$ So, hourly temperatures never exceed 25$^\circ$C? A quadratic would be better than linear, but that was not what I was suggesting. You need to see what the relationship is before you can decide how best to model it. $\endgroup$
    – Nick Cox
    Aug 26, 2016 at 11:53

1 Answer 1

2
$\begingroup$

You obviously have a large amount of data. In such cases, a good alternative to the scatterplot is pre-binning the data, e.g., in hexagons. I recommend the hexbin package for R, which will give you a hexbinplot like this:

hexbinplot

library(hexbin)

set.seed(1)
x <- rnorm(20000)
y <- rnorm(20000)
hbin <- hexbin(x,y, xbins = 40)
plot(hbin)

mkt asks why we should use hexagons, rather than, say, squares. Here is the argument made in the hexbin vignette:

Hexagons have symmetry of nearest neighbors which is lacking in square bins. Hexagons are the maximum number of sides a polygon can have for a regular tesselation of the plane, so in terms of packing a hexagon is 13% more efficient for covering the plane than squares. This property translates into better sampling efficiency at least for elliptical shapes. Lastly hexagons are visually less biased for displaying densities than other regular tesselations. For instance with squares our eyes are drawn to the horizontal and vertical lines of the grid.

The vignette offers the following example to underline the last point:

hexes vs squares

$\endgroup$
6
  • $\begingroup$ (+1) Is there anything special about hexagons? I like these plots, but don't understand why we don't use squares (for example). $\endgroup$
    – mkt
    Sep 18, 2019 at 10:42
  • 1
    $\begingroup$ Classically there are three tessellations (tilings) of regular convex polygons that fill the plane: triangles, squares and hexagons. Any preference for hexagons seems as much aesthetic or psychological as statistical. It's often asserted that horizontal and vertical striping are distracting. $\endgroup$
    – Nick Cox
    Sep 18, 2019 at 10:54
  • 1
    $\begingroup$ @mkt: good point. See my edit. $\endgroup$ Sep 18, 2019 at 11:44
  • 1
    $\begingroup$ I quite like these plots too. But it seems to me that the major issue remains using smoothing to estimate a curve for (e.g.) demand as a function of temperature. The relationship isn't likely to be linear! It seems less likely that demand depends directly on price. Time series information -- and indeed substantive information on pricing decisions -- is surely needed. $\endgroup$
    – Nick Cox
    Sep 18, 2019 at 12:51
  • 1
    $\begingroup$ @NickCox: I agree that there is probably little "linear" relationship here, which is why I focused on the "how to plot the data" aspect. A hexbinplot may show nonlinearity in a very obvious way. $\endgroup$ Sep 18, 2019 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.