R Question

Bar plot with two factors with gradient color in R

I have a data frame like this:

df = data.frame(time = rep(0.5:9.5, each = 10), roi = rep(1:10, 10), area = runif(100, 5.0, 7.5))

I would like to draw a plot including 10 bars of 10 values of
. In this case, x-axis will be
, y-axis will be
, and the values of
will be showed in bars with gradient color (highest = white, lowest = black). The y-axis is reversed from 0.5 top to 9.5 bottom, width of bar is 2.

The expected figure looks like
this image.

I am looking forwards to replies and I appreciate your all helps.

Answer Source

Is this what you had in mind?

df=data.frame(time=as.factor(rep(0.5:9.5,each=10)),roi=rep(1:10,10),area=runif(100, 5.0, 7.5))

df$time <- factor(df$time, levels=rev(levels(df$time)))

ggplot(data=df, aes(y=factor(roi), x=time, fill = area)) +
  theme_minimal()  + coord_flip() +
  geom_tile(colour = "white", width = .9, height = 1) + 

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download