user20512192
user20512192

Reputation:

How to have all years displayed on the x-axis?

How can I include all of the years on the x-axis in my plot?

enter image description here

Here is my code:

library(tidyverse)
dados %>% select(1:4)

dadosrestricao <- dados %>% select(1:4)

dadosrestricao

str(dadosrestricao)

str(dadosrestricao)

library(ggplot2)
library(dplyr)
library(hrbrthemes)

install.packages("hrbrthemes")
str(dadosrestricao)
# Plot



ggplot(dadosrestricao,aes(x=Year,y=EYPR_EUROSTAT,group=Country))+
  geom_line(aes(color=Country)) +
  geom_point(aes(color=Country)) 

this ggplot was what i knew how to do, beyond that i don t what code i need

thanks a lot for the help

Upvotes: 0

Views: 520

Answers (1)

asd-tm
asd-tm

Reputation: 5263

As there is no data provided I would offer this sample data graph assuming that your dates can be continuous, not years only factor:

library(ggplot2)
library(dplyr) 
library(lubridate) 


economics %>% 
filter(date %in% as.Date("1970-01-01"):as.Date("1979-12-31"))%>%
ggplot() +
geom_line(aes(x=date, y=pop)) +
scale_x_continuous(labels = 1970:1980, breaks = seq.Date(from = as.Date("1970-01-01"), to = as.Date("1980-01-01") , by = "1 year")) 

The idea is to specify the x axis with all necessary details including all necessary breaks and labels.

Upvotes: 1

Related Questions