The scale_x_discrete
function does not have a second axes argument, but scale_x_continuous
does. So editing the type
variable to a numeric variable and then changing the label would work:
d<- data.frame (pid=c("d","b","c"), type=1, value = c(1,2,3) )
d2 <- data.frame (pid=c("d","b","c"), type= 2, value = c(10,20,30) )
df <- rbind (d,d2)
ggplot(df, aes(y=pid, x=type)) +
geom_tile(aes(fill = value),colour = "white") +
scale_fill_gradient(low = "white",high = "steelblue") +
scale_x_continuous(breaks = 1:2,
labels = c("rna", "dna"),
sec.axis = dup_axis())