Question

With that data below, I need to have a scatterplot with each item in the "Name" column labeling their corresponding XY plot. The Goal Column would represent group coloring, as indicated by the legend. I'm new at R and have gotten only as far as plotting X and Y.

X    Y  Name    Goal                Color   
0.582   30  FS1Br1  Acummulation        BLUE    
0.612   33  FS1Br2  Acummulation        BLUE    
0.725   28  FS1Br3  Acummulation        BLUE    
0.532   27  FS1Br4  Acummulation        BLUE    
0.615   30  FS1Br5  Acummulation        BLUE    
0.562   23  FS2Br1  Processing          GREEN   
0.653   22  FS2Br2  Processing          GREEN   
0.66    25  FS2Br3  Processing          GREEN   
0.595   21  FS2Br4  Processing          GREEN   
0.665   30  FS2Br5  Processing          GREEN   
0.581   26  FS2Br6  Processing          GREEN   
0.684   32  FS2Br7  Processing          GREEN   
0.62    26  FS3Br1  Data Analysis       YELLOW  
0.733   27  FS3Br2  Data Analysis       YELLOW  
0.59    23  FS3Br3  Data Analysis       YELLOW  
0.582   22  FS3Br4  Data Analysis       YELLOW  
0.595   20  FS3Br5  Data Analysis       YELLOW  
0.639   18  FS3Br6  Data Analysis       YELLOW  
0.625   22  FS3Br7  Data Analysis       YELLOW  
0.585   33  FS4Br1  Value Add Insights  RED 
0.61    24  FS4Br10 Value Add Insights  RED 
0.649   26  FS4Br2  Value Add Insights  RED 
0.576   26  FS4Br3  Value Add Insights  RED 
0.596   31  FS4Br4  Value Add Insights  RED 
0.5     32  FS4Br5  Value Add Insights  RED 
0.673   24  FS4Br6  Value Add Insights  RED 
0.696   21  FS4Br7  Value Add Insights  RED 
0.681   28  FS4Br8  Value Add Insights  RED 
0.571   28  FS4Br9  Value Add Insights  RED

Here's the code I've tried to use so far:

plot(data$X,
     data$Y,
     pch=1,
     cex=1.0,
     bg="black",
     col="black",
     xlab="Correlation Coefficient",
     ylab="Top-Box %",
     main="Google")
Was it helpful?

Solution

If df is your data set, you can try ggplot2 package

library(ggplot2)
ggplot(data = df, aes(x = X, y = Y,  label = Name)) + 
  geom_point() + 
  scale_colour_manual(values = c("blue", "green", "yellow", "red")) +
  geom_text(aes(color = Goal), hjust=1.1, vjust=1.1, size = 5) +
  labs(title = "Google", x = "Correlation Coefficient", y = "Top-Box %")

enter image description here

A bit different version where the points are the same color as names

library(ggplot2)
ggplot(data = df, aes(x = X, y = Y, color = Goal)) + 
  geom_point() + scale_colour_manual(values = c("blue", "green", "yellow", "red")) +
  geom_text(aes(label = Name), hjust=1.1, vjust=1.1, size = 5) +
  labs(title = "Google", x = "Correlation Coefficient", y = "Top-Box %")

enter image description here

Third version where the labels are black

library(ggplot2)
ggplot(data = df, aes(x = X, y = Y,  color = Goal)) + 
  geom_point() + 
  scale_colour_manual(values = c("blue", "green", "yellow", "red")) +
  geom_text(aes(label = Name), color = "black", hjust=1.1, vjust=1.1, size = 5) +
  labs(title = "Google", x = "Correlation Coefficient", y = "Top-Box %")

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top