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

2
  • 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 (not as an image) so we can easily run/test the code. Commented Jul 26, 2020 at 0: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. Commented Jul 26, 2020 at 6:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.