plot with ggplot2
0
0
Entering edit mode
6.2 years ago
erick_rc93 ▴ 30

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)") +
   ggtitle("random-name"))+
   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 • 1.2k views
ADD COMMENT
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 1693 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6