Home > Software engineering >  geom_point and geom_line not showing even after specifying group =1
geom_point and geom_line not showing even after specifying group =1

Time:05-18

The df looks like this:

(Year is 'character' type and mean is double )

Year mean
11-12 0.3625971
13 0.3584357
14-15 0.3667632
16-17 0.3039611
18-19 0.3169676
21 0.2649566

Reproducible example (dput):

    structure(list(Year = c("11-12", "13", "14-15", "16-17", "18-19", "21"), mean = c(0.362597098050711, 0.358435740662268, 0.36676321506155, 0.303961136023916, 0.316967585260268, 0.264956571150256)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -6L))

The code:

df %>% 
  ggplot(aes(x = Year, y = mean, group = 1))  
    geom_line()

The plot:

enter image description here

CodePudding user response:

Seems to work fine with ggplot

library(tibble)
library(ggplot2)

df1 <- tribble(
~Year, ~mean,
"11-12",    0.3625971,
"13",   0.3584357,
"14-15",    0.3667632,
"16-17",    0.3039611,
"18-19",    0.3169676,
"21",   0.2649566)


ggplot(df1, aes(Year, mean)) 
  geom_point()


ggplot(df1, aes(Year, mean, group = 1)) 
  geom_line()

Created on 2022-05-17 by the enter image description here

The reason is that I once set the theme using theme_set(dark_theme_gray()), a theme from the ggdark library, where the points are in white. It's possible that the color of the points was preserved even after I changed the theme to theme_classic() using theme_set(theme_classic())

To fix this, run this:
theme_set(invert_geom_defaults()) before setting a new theme.

  • Related