Reputation: 449
I have two data tables in the form of Columns namely pair of Diseases and their measures as a pair. Below is the first one(sample data) disease_table1
**d1** **d2** **Value**
Disease1 Disease2 3.5
Disease3 Disease4 5
Disease5 Disease6 1.1
Disease1 Disease3 2.4
Disease6 Disease2 6.7
the real Dataset 1(disease_table1) is below:
Bladder cancer X-linked ichthyosis (XLI) 3.5
Leukocyte adhesion deficiency (LAD) Aldosterone synthase Deficiency 1.8
Leukocyte adhesion deficiency (LAD) Brain Cancer 1.5
Tangier disease Pancreatic cancer 0.66
I want to show the difference between these two data tables while plotting the disease pairs and its values for both tables. I used the plot function and lines function but its too simple,and is not able to differentiate much.Also I would like to have the names of the disease pairs while plotting.
plot(density(disease_table1$value))
lines(density(disease_table1$value))
Thanks
Upvotes: 0
Views: 160
Reputation: 83275
Some sample code:
# creating dataframes (i made up a second one)
df1 <- read.table(text = "d1 d2 x
Disease1 Disease2 3.5
Disease3 Disease4 5
Disease5 Disease6 1.1
Disease1 Disease3 2.4
Disease6 Disease2 6.7", header = TRUE, strip.white = TRUE)
df2 <- read.table(text = "d1 d2 y
Disease1 Disease2 4.5
Disease3 Disease4 2
Disease5 Disease6 3.1
Disease1 Disease3 1.4
Disease6 Disease2 5.7", header = TRUE, strip.white = TRUE)
# needed libraries
library(reshape2)
library(ggplot2)
# merging dataframes & creating unique identifier variable
data <- merge(df1, df2, by = c("d1","d2"))
data$diseasepair <- paste0(data$d1,"-",data$d2)
data.long <- melt(data, id="diseasepair", measure=c("x","y"), variable="group")
# make the plot
ggplot(data.long) +
geom_bar(aes(x = diseasepair, y = value, fill = group),
stat="identity", position = "dodge", width = 0.7) +
scale_fill_manual("Group\n", values = c("red","blue"),
labels = c(" X", " Y")) +
labs(x="\nDisease pair",y="Value\n") +
theme_bw()
The result:
Is this what you're lookin for?
Upvotes: 2