0

I am a beginner in R, and have only been doing it for a couple weeks. Recently I have been trying to engage with more advanced R material for my work in bioinformatics. I found out about ggplot and ggtree, so I started reading about them and practice on some simpler examples.

I have been trying out some pre-written example codes before applying it to my own work for my research.

What confuses me is that I did not even use the function 'scale_fill_gradient()' yet I keep getting this error message every time I try to run it. I even tried to attach this to my original code and pressed 'tab' to see if there is anything I could try the function with but nothing seems to work.

Apologies if this seems like a stupid question to a fundamental issue, but as I said I have no previous programming experience. However, some R knowledge is required for my research.

Thank you very much!

I tried looking up solution on here, and even though there were posts mentioning issues with the very same error code, I cannot really interpret it.

The code is as follows:

library(treeio) # Bioconductor
library(ggtree) # Bioconductor
library(viridis)

nwk <- system.file("extdata", "sample.nwk", package="treeio")

tree <- read.tree(nwk)
circ <- ggtree(tree, layout = "circular")

df <- data.frame(first=c("a", "b", "a", "c", "d", "d", "a", "b", "e", "e", "f", "c", "f"),second= c("z","z","z","z", "y", "y", "y", "y", "x", "x", "x", "a", "a"))
rownames(df) <- tree$tip.label

df2 <- as.data.frame(matrix(rnorm(39), ncol=3))
rownames(df2) <- tree$tip.label
colnames(df2) <- LETTERS[1:3]


p1 <- gheatmap(circ, df, offset=.8, width=.2, colnames_angle=95, colnames_offset_y = .25) + scale_fill_viridis(option="D", name="discrete\nvalue")


library(ggnewscale)
p2 <- p1 + new_scale_fill()
gheatmap(p2, df2, offset=15, width=.3, colnames_angle=90, colnames_offset_y = .25) +
scale_fill_viridis(option="A", name="continuous\nvalue")

And the error message:

Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
Error in `scale_fill_gradientn()`:
! Discrete values supplied to continuous scale.
ℹ Example values: "f", "e", "e", "f", and "c"

1
  • 4
    You need scale_fill_viridis(option="D", discrete = TRUE, name = "discrete\nvalue"), then it will work. Commented Mar 11 at 14:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.