0

I am trying to make a scatter plot with ggplot to show time watching TV on x axis and immigrant sentiment on y axis.

The code I am using is

ggplot(totalTV, 
       aes(x = dfnew.TV.watching..total.time.on.average.weekday, 
           y = dfnew.Immigrant.Sentiment)) + 
  geom_point()

I am getting this output

The scatterplot

My table is so, with first variable being character, and subsequent two being numeric:

My table is so

Any idea on how to produce a representative scatter of the outcome?

Cheers

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
J1997
  • 15
  • 1
  • 4
  • 1
    The scatter plot looks correct for your data but it seems like a scatter plot might not be the best choice when you have two discrete variables like that. What are you trying to show exactly? Also, be sure to share example data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (not as an image) so we can easily run/test the code. – MrFlick Jul 26 '20 at 00:36
  • 1
    If there are overlapping points, you may wish to consider `geom_jitter` instead of `geom_point`, perhaps with `alpha = 0.5` (or any other number < 1), so that the data spread becomes clearer. – Z.Lin Jul 26 '20 at 06:49

1 Answers1

3

Here are some examples using the mtcars dataset.

library(ggplot2)

# Original
ggplot(mtcars,aes(factor(cyl),mpg)) + 
  geom_point()

# Jitter
ggplot(mtcars,aes(factor(cyl),mpg)) + 
  geom_jitter(width = .2) # Control spread with width

# Violin plot
ggplot(mtcars,aes(factor(cyl),mpg)) + 
  geom_violin()

# Boxplot 
ggplot(mtcars,aes(factor(cyl),mpg)) + 
  geom_boxplot()


# Remember that different geoms can be combined
ggplot(mtcars,aes(factor(cyl),mpg)) + 
  geom_violin() + 
  geom_jitter(width = .2)

# Or something more exotic ala Raincloud-plots
# https://micahallen.org/2018/03/15/introducing-raincloud-plots/

enter image description here

Magnus Nordmo
  • 923
  • 7
  • 10