4

I am trying to create an an isotherms plot using the ggplot2 package, you can find an example showing the desired result in the comments. I've seen many examples for doing so online, such as:

data <- read.table("http://s000.tinyupload.com/download.php?file_id=01371475872599670620&t=0137147587259967062053048", header=TRUE)

ggplot(data) + aes(x=x, y=y, z=z, fill=z) + stat_contour() + geom_tile()

When I use the exact same code with my data I get the following result:

Image:

graph with isolines

As you can see in the image above, the data seems to work with the stat_contour() part, which looks perfect, but it does not work with geom_tile(), which only seems to create those three horizontal lines. The data seems to be read correctly, since the contour lines work and the legend contains the right values too. I don't know why the files won't be filled though.

I'd really appreciate any help provided, thanks!

oepix
  • 151
  • 2
  • 12
  • 1
    A question should be self-contained without relying on external sites. Please share your data inside your question. See [this FAQ](http://stackoverflow.com/a/5963610/1412059) about good ways to do that. – Roland Sep 20 '15 at 13:26
  • Example: http://de.tinypic.com/r/2sb3daq/8 – oepix Sep 20 '15 at 13:31
  • I'm sorry for the use of external sites. Due to my lack of reputation, I was simply not able to add the images to the text. As for the dataset: There are no problems with other datasets, just with this specific one I am trying to use. – oepix Sep 20 '15 at 13:31
  • I (and others) won't go to an external upload service to get your data. – Roland Sep 20 '15 at 13:38
  • I can fully understand why one wouldn't. Are there any speculations on why the contours are being drawn correctly while the tiles are not though? – oepix Sep 20 '15 at 13:47
  • @Roland here's a safe read for the data: `dat <- read.table("http://s000.tinyupload.com/download.php?file_id=01371475872599670620&t=0137147587259967062053048", header=TRUE)` (`lynx` & being a paranoid infosec person FTW :-). 760 rows wld have been a bit much to `dput()` – hrbrmstr Sep 20 '15 at 14:11

1 Answers1

10

It's probably happening due to the irregular grid. Try interpolating the values first then doing the plot:

library(ggplot2)
library(akima)
library(viridis)
library(ggthemes)

dat <- read.table("http://s000.tinyupload.com/download.php?file_id=01371475872599670620&t=0137147587259967062053048", header=TRUE)

di <- interp(dat$x, dat$y, dat$z,
             xo=seq(min(dat$x), max(dat$x), length=200),
             yo=seq(min(dat$y), max(dat$y), length=200))

dat_interp <- data.frame(expand.grid(x=di$x, y=di$y), z=c(di$z))

ggplot(dat_interp) +
  aes(x=x, y=y, z=z, fill=z) +
  geom_tile() +
  stat_contour(color="white", size=0.25) +
  scale_fill_viridis() +
  theme_tufte(base_family="Helvetica")

enter image description here

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205