Question: plot with ggplot2
gravatar for erick_rc93
5 months ago by
erick_rc930 wrote:

I have merged two data.frames with the same column names but different number and name of rownames in R, and I have made a scatter plot in ggplot, but I'd like two have two different colour of dots in the plot

model_3 <- rbind(df_1,df_2)

 plot  <- ggplot(data=model_3, aes(x=model_3[,"log(obs/exp)"], y=model_3[,"log(obs-exp)^2/exp)"],colour = model_3[,"log(obs/exp)"]))+geom_point()+
   geom_text(label=rownames(model_3), hjust = 0, nudge_x = 0.05, size = 1.5) +
   labs(colour = "log(obs/esp)",size = 0.5) +
   labs(x = "log(obs/esp)") +
   labs(y="log(obs-exp)^2/exp)") +
   xlim(-11, 16)+ylim(-11,16) + 
   theme(panel.background = element_rect(fill = "white", colour = "grey50"))

above I show the code that I'm using, but this only adds color according to the values of a column, but I want them to be colored with respect to the names of each dataframe that was merged.

R • 227 views
ADD COMMENTlink written 5 months ago by erick_rc930

Can you show head(df1) & head(df2)?

Seems like you can add add one more column to each data.frame e.g.

df1$SOURCE <- "df1"
df2$SOURCE <- "df2"

model_3 = rbind(df1, df2)

Then color based on SOURCE

ADD REPLYlink modified 5 months ago • written 5 months ago by venu6.1k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1111 users visited in the last hour