Hi All,
I wrote a code to plot a matrix graph but after running the code, plot doesn't match with the matrix data. I don't able to figure out the problem. If anyone knows how to resolve it then it would be highly appreciated. R-code is:
# install.packages("ggcorrplot")
# install.packages("ggplot2")
library(ggplot2)
library(ggcorrplot)
data <- read.csv(file="C:/Users/sinha.puja/Desktop/ChromHMM/practice.csv", sep=",")
rnames <- data[,1]
mat_data <- data.matrix(data[,2:ncol(data)])
rownames(mat_data) <- rnames
mat_data <- expand.grid(mark = c("H3K27me3", "H3K9me3", "H3K36me3"),
state = c("TssP", "PcRepr", "Heter/low", "EnhP/low", "ConHeter"))
mat_data$Probability <- rnorm(nrow(mat_data))
ggplot(data = mat_data, aes(x = mark, y = state)) +
geom_tile(aes(fill = Probability), colour="grey80") +
scale_fill_gradient(low="white", high="red")
The input dataset is as follows:
state (Emission order) H3K27me3 H3K9me3 H3K36me3
TssP 0.525472473 0.013872603 0.012417431
PcRepr 0.028550739 0.004967125 0.000949458
Heter/low 0.001659524 0.002706355 0.000396299
EnhP/low 0.004981548 0.183992447 0.002332633
ConHeter 0.118632661 0.82344082 0.395105767
Please help me in plotting the matrix without changing the input values.
I don't understand what you mean by "plot doesn't match matrix code".
It would probably be helpful if you:
mat_data
(e.g.head(mat_data)
)Hi, please make use of the formatting buttons that are available. I've edited your post to properly show the code portions; in the future you can do that yourself by using the button next to the quotation marks.
Hi, Thank you for your effort. Below is the image published from the article, similar one I want to create with my data. If that makes sense what I want to illustrate and its clear too then please help me in plotting similar type of image.
I will highly appreciate.
I do not know what the values represent that you have in your matrix, but since you're complaining that the
rnorm
values aren't it, what's wrong with this:Hi, I have modified the codes with the values as mentioned below:
I do not know how to edit the step bold above and also in ggplot step, x = mark has to be used. Kindly help me in the test.long step which has marked with bold. Sorry for not presenting it properly.
since you no longer have a column named "Emission", did you try what happens by just removing that entry from the reshape command? If you want to keep the column with the histone mark labels named "mark", you'll have to add
variable.name = "mark"
to thereshape2:melt
command.