Joezerz
Joezerz

Reputation: 151

Change contour colours using directlabels

I'm fairly new to ggplot2, and I'm trying to create a contour plot of data that has missing values. Because there's missing values I can't have the contours by themselves, so I'm combining a tiles background with a contour. The problem is the labels are the same colour as the background.

Suppose I have data like so:

DF1 <- data.frame(x=rep(1:3,3),y=rep(1:3,each=3),z=c(1,2,3,2,3,4,3,NA,NA))

I can make a plot like this:

require(ggplot2); require(directlabels)
plotDF <- ggplot(DF1,aes(x,y,z=z)) + geom_tile(aes(fill=z)) + stat_contour(aes(x,y,z=z,colour= ..level..),colour="white")
direct.label(plotDF)

This gives me a plot similar to what I want but I'd like to be able to change the colours of the labels to be black. Any ideas?

Upvotes: 1

Views: 488

Answers (1)

tonytonov
tonytonov

Reputation: 25608

I spotted a similar post and thought this would be easy, something along the lines of direct.label(p, list("last.points", colour = "black"). I could not make it work, unfortunately; I believe, this is not directly supproted.

I then decided to use black magic and managed to do the trick by manually overriding the colour scale:

direct.label(plotDF + 
             scale_colour_gradient(low="black", high="black"))

enter image description here

Upvotes: 1

Related Questions