Graph by ggplot in Rstudio v 1.1.463 does not read Subtitle and caption in Labs()

Asked

Viewed 1,089 times

1

I have the problem reported in the title and, I do not understand why in Rstudio Subtitle and caption are not read. When I replay the code in Visual Studio, it correctly loads all the commands - the graph is exactly as it is in the code.

Follow the code and an excerpt of the data to replicate in Rstudio:

ggplot(Endividamento_Familias_Mensal, aes(Data, 
Endividamento_Familias)) +
  geom_line() +
  labs(title = "Endividamento Familiar", caption = "Fonte: PNADC - 
Bacen")

The data is:

inserir a descrição da imagem aqui

This same code, with the same data, executed by Visual Studio, generates the graph correctly.

See how it looks for Rstudio:

inserir a descrição da imagem aqui

  • In this case, it is the caption that does not appear.... The Subtitle did not put in this case.

  • 2

    Post the time series data, not her print.

  • 2

    Can you please, edit the question with the departure of dput(Endividamento_Familias_Mensal) or, if the base is too large, dput(head(Endividamento_Familias_Mensal, 20))?

  • 3

    On my machine caption works correctly, see here: https://imgur.com/a/di3nWH9. I suggest you update ggplot2 as well as check your version of R. Amid sessionInfo() on the console at Rstudio. Mine ggplot2 is version 2.2.1 and R version 3.5.0.

  • 2

    Try Endividamento_Familias_Mensal$Data <- as.Date(Endividamento_Familias_Mensal$Data, "%d/%m%/Y"). If the column data is a class object "Date", works perfectly with me.

1 answer

3


The argument caption was inserted into the version 2.2, which is November 2016 (source).

According to some comments, it is not a mistake in Rstudio. Most likely, without knowing the sessionInfo(), is that the version used of R by the Visual Studio shell and Rstudio are different and the latter the available ggplot2 is less than 2.2.

You can check the version of which is being used in Rstudio with the beginning R.version[["version.string"]]. You can change the version used in Rstudio in the menu Tools > Global Options.... On the tab General choose the version of R desired.

To check the version of ggplot2 that is being used, just rotate installed.packages()["ggplot2", "Version"]. Make sure the number is higher than "2.2".

  • 1

    Tomás, thank you so much. Really it was the version of ggplot2 on Rstudio. Great new year and success and prosperity for you and your family.

  • 1

    You are welcome. Accept the answer to help users search for information in the future.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.