-1

I am having an issue when trying to produce a scatter plot from 2 variables. The data is from an excel file. One column/variable is "Contact Method", where the cell value is text, from a multiple choice option (e.g. phone, email) Another is a numerical rating, such as from 0-50 for "feel valued"

Here is the code I have used:

 ggplot(cxfiltered111) + 
      geom_point(aes(x = ContactMethod, y = CXRecommend, fill = ContactMethod)) + 
      ylab(NULL) + 
      xlab(NULL) +  
      coord_flip() + 
      theme_bw() + 
      labs(title = "Relationship between contact method and feeling valued")

Click here for Scatterplot image Dataset example is available here - https://drive.google.com/file/d/1-i8rulX47mrFtgET_DIW3rsR8ql_xKTh/view?usp=sharing

Of course this isn't correct, I feel this is something to do with the data type (e.g. categorical/factor). However I have no idea how to convert this data to the correct data type to produce a legitimate graph. Please help

ZC-
  • 9
  • 2
  • Welcome to StackOverflow :) Providing your data (or an example dataset) is always crucial when asking a question in R. I would recommend reading this for some suggestions on how to ask a great question: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example-aka-mcve-minimal-complete-and-ver – Michael Harper Nov 27 '17 at 00:07
  • Also , you say "Of course this isn't correct". Can you want to be more specific in your issue? Scatterplots are designed for plotting X Y data, not categorical data. – Michael Harper Nov 27 '17 at 00:09
  • Hey @ZC-, has my answer solved your problem? Please mark it as accepted if it has :) – Michael Harper Nov 27 '17 at 20:25

1 Answers1

1

As you haven't provided any data to use, here is some sample data:

df <- data.frame(Contact = c("Social Media", "Phone", "Other", "Letter", "Email"),
                 Score = sample(1:100,100,replace=T))

Now recreating your graph with the basic code (no formatting or changing coordinates):

ggplot(df, aes(x = Contact, y = Score, fill = Contact)) +
  geom_point()

enter image description here

Two problems:

  1. You are trying to set the aesthetic of a point will fill. You need to change colour
  2. The bigger problem: I am not sure scatterplots are what you really want to be using for such data. As you have pointed out, the data is categorical.

A boxplot is probably the better way to go about this:

ggplot(df, aes(x = Contact, y = Score, fill = Contact)) +
  geom_boxplot()

enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84