0
votes

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.

1
use tidyr::gather to put all your y variables in one column, then facet by variable - Richard Telford
Welcome to Stack Overflow! Please read the info about how to ask a good question and how to give a reproducible example. This will make it much easier for others to help you. - zx8754

1 Answers

1
votes

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.