Combine Points with lines with ggplot2

前端 未结 3 990
一生所求
一生所求 2020-12-05 07:03

I would like to plot a time series that look like this:

\"enter

what I plot wi

相关标签:
3条回答
  • 2020-12-05 07:17

    A small change to Paul's code so that it doesn't return the error mentioned above.

    dat = melt(subset(iris, select = c("Sepal.Length","Sepal.Width", "Species")),
               id.vars = "Species")
    dat$x <- c(1:150, 1:150)
    ggplot(aes(x = x, y = value, color = variable), data = dat) +  
      geom_point() + geom_line()
    
    0 讨论(0)
  • 2020-12-05 07:22

    You may find that using the `group' aes will help you get the result you want. For example:

    tu <- expand.grid(Land       = gl(2, 1, labels = c("DE", "BB")),
                      Altersgr   = gl(5, 1, labels = letters[1:5]),
                      Geschlecht = gl(2, 1, labels = c('m', 'w')),
                      Jahr       = 2000:2009)
    
    set.seed(42)
    tu$Wert <- unclass(tu$Altersgr) * 200 + rnorm(200, 0, 10)
    
    ggplot(tu, aes(x = Jahr, y = Wert, color = Altersgr, group = Altersgr)) + 
      geom_point() + geom_line() + 
      facet_grid(Geschlecht ~ Land)
    

    Which produces the plot found here:

    enter image description here

    0 讨论(0)
  • 2020-12-05 07:29

    The following example using the iris dataset works fine:

    dat = melt(subset(iris, select = c("Sepal.Length","Sepal.Width", "Species")),
          id.vars = "Species")
    ggplot(aes(x = 1:nrow(iris), y = value, color = variable), data = dat) +  
          geom_point() + geom_line()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题