1

I am using ggplot and geoms to show my data, but the plot sidebar area just shows a gray box with the x and y axis correctly labeled.

Here is the output image:

gray plot area

The code which made the plot:

ggplot(Wc, aes(y = popsafe, x = rnground)) +
   geom_jitter(aes(col = me)) +
   geom_smooth(method = "lm", se = FALSE, col = "black")
Michael Harper
  • 14,721
  • 2
  • 60
  • 84
Ashley F
  • 45
  • 7
  • 4
    Welcome to SO! It's very difficult to help, since we have no data to test with. Please read one of: https://stackoverflow.com/help/how-to-ask, https://stackoverflow.com/help/mcve, and/or (perhaps most helpful) https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example, then come back and edit your question. – r2evans Apr 05 '18 at 04:10
  • 3
    You're missing a `geom_point(...)` or `geom_line(...)` in your `ggplot` command to actually draw the data. – Maurits Evers Apr 05 '18 at 04:24
  • This typically happens when you use `ggplot()` without an associated geom, as @MauritsEvers suggested, so I don't know that your example code leads to your example output. – neilfws Apr 05 '18 at 04:28
  • 1
    @MauritsEvers Both `geom_jitter()` and `geom_smooth()` draw data. – Claus Wilke Apr 05 '18 at 05:06
  • @ClausWilke Yup, you're absolutely right. I just superficially screened for `geom_line` and `geom_point` and then drew the wrong conclusion. It seems you got to the bottom of things in your answer. – Maurits Evers Apr 05 '18 at 05:15

1 Answers1

2

Looks like your dataset is empty. We don't know what your dataset contains, so here an example with the built-in iris dataset. First a proper plot, using the same geoms and mappings you use:

library(ggplot2)
ggplot(iris, aes(y = Sepal.Length, x = Sepal.Width)) +
  geom_jitter(aes(col = Species)) +
  geom_smooth(method = "lm", se = FALSE, col = "black")

enter image description here

Now I remove all the data from the dataset and replot:

library(dplyr)
iris_empty <- filter(iris, Sepal.Length < 0)
ggplot(iris_empty, aes(y = Sepal.Length, x = Sepal.Width)) +
  geom_jitter(aes(col = Species)) +
  geom_smooth(method = "lm", se = FALSE, col = "black")

enter image description here

A simple head(Wc) would confirm whether your dataset actually contains any data.

Claus Wilke
  • 16,992
  • 7
  • 53
  • 104