Skip to content
Prev 384664 / 398525 Next

unique scale color ggplot2

On 2020-07-07 12:44 +0200, Thierry Onkelinx via R-help wrote:
Hmm ... what might df1 have looked like 
... creating a df with columns spei, 
month, cor, and zCuts containing 1:5 
doesn't do the trick ... 

	df1 <-
	  data.frame(
	    spei=1:5,
	    month=1:5,
	    cor=1:5,
	    zCuts=1:5
	  )
	cols <-
	  c("#0288D1", "#039BE5",
	    "#03A9F4","#29B6F6", "#4FC3F7",
	    "#FFCDD2", "#E57373", "#F44336",
	    "#E53935", "#D32F2F", "#C62828",
	    "#B71C1C")
	zCuts <- seq(-.5, 0.6, by=0.1)
	filename <- "/tmp/catalin1.png"
	width <- 800
	height <- 600
	res <- 150
	png(filename=filename, width=width, height=height, res=res)
	mapping <- ggplot2::aes(
	  x = as.factor(spei),
	  y = as.factor(month),
	  fill = cut(cor, zCuts)
	)
	p <- ggplot2::ggplot(df1, mapping=mapping) +
	   ggplot2::geom_tile() +
	   ggplot2::scale_fill_gradient(limits = c(-0.7, 0.7))
	#   ggplot2::scale_fill_manual(values=cols)
	p
	dev.off()

... which only produces the error

	Error: Discrete value supplied to continuous scale
	Execution halted

V

r