Display names with multiple dataframe

Hello everybody,

I have two dataframes and I'd like to put them on the same scatterplot ggplot. However, I'd like to display the names of the point (third column of both dataframes) , but only for the points belonging to the "df2" data.frame. Is it possible ? Here's my code and my dataframes.

Thanks you for reading !

Robin

########################################################################################
df1<-data.frame("Rendement" = c(0.1,0.15,0.2), "Risque" = c(0.05,0.03,0.15), "Name" = c("Fufu","Wayowayo","Otacos"))

df2<-data.frame("Rendement" = c(0.12,0.11,0.25), "Risque" = c(0.14,0.0325,0.17), "Name" = c("Pictet","Interselection","Carlton"))

p <- ggplot(NULL, aes(Risque,Rendement), label = Name)+
geom_point(data = df1, colour = "orange", size = 2)+
geom_point(data = df2, colour = "blue", size = 2)+
expand_limits(x = 0, y = 0)+
labs(title = 'Frontiere efficiente', x = 'Volatilite journaliere', y = 'Rendement journalier ')+
scale_y_continuous(labels = percent)+
scale_x_continuous(labels = percent)+
theme(plot.title = element_text(face = 'bold.italic', hjust = 0.5))
ggplotly(p)
################################################################################

Do you mean something like that?
Note: variable percent is not defined in your sample data, so I commented scale_*_continuous() lines to prevent the error.

p <- ggplot(data = NULL, aes(x = Risque,
                             y = Rendement))+
  geom_point(data = df1, colour = "orange", size = 2)+
  geom_point(data = df2, colour = "blue", size = 2)+
  geom_text(data = df2, aes(label = Name),  colour = "blue", hjust=0, vjust=0)+
  expand_limits(x = 0, y = 0)+
  labs(title = 'Frontiere efficiente',
       x = 'Volatilite journaliere',
       y = 'Rendement journalier ')+
  #scale_y_continuous(labels = percent) +
  #scale_x_continuous(labels = percent) +
  theme(plot.title = element_text(face = 'bold.italic', hjust = 0.5))
1 Like

This is perfectly working. Thanks a lot !

I also would like to make possible to "click" on the plot and draw a dot at the place the click occured. Could you tell me if it's possible and how to do it ? (also I I click a second time at another place on the plot, the first dot has to vanish)

I'm never worked with dynamic plots, so can't help with that.
I would suggest creating a new topic with this question, otherwise, people may not see it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.