0

I have a dataframe, df, with 17 observations of 12 variables. Every observation represents the value assumed by a variable in a year, I have years from 1995 to 2011.

I would like to plot some of those variables having on the x axis always the year, and on the y axis the values of the variables. I would like to have it like facets, in a single graph.

How can I do it? I used ggplot2 to plot one of those variables.

The code I've written:

ggplot(c4ItaGerFinale, aes(Anno,EXPtot)) +
  geom_point(color = "steelblue", size=2) +
  labs(x= "Anno", y= "Milioni di dollari", title = "Settore Tessile, wiod c4") +
  coord_cartesian(ylim=c(0,6000))

Where EXPtot is a variable, Anno is the variable I would like to have always on the x axis, and c4ItaGerFinale is my data.frame.

Francesco
  • 59
  • 2
  • 9
  • 2
    use `tidyr::gather` to put all your y variables in one column, then facet by variable – Richard Telford Sep 23 '16 at 14:42
  • Welcome to Stack Overflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Sep 23 '16 at 15:05

1 Answers1

1

As suggested by user @Richard Telford I used gather to put all my variables in a column, then facet by variable.

dfgraph <- gather(df, Variable, Name, 2:12)

then used ggplot.

Francesco
  • 59
  • 2
  • 9