How to fix the x-axis boundaries in ggplot?

Asked

Viewed 3,637 times

3

I have the following data:

k <- c(294131, 734127, 817963)
ano <- c(1991, 2000, 2010)
dados <- data.frame(k, ano)

I’m doing it this way:

ggplot(dados,aes(x=ano,y=k)) + geom_point() + geom_line() + scale_x_continuous(limits=c(1991, 2010))

But the graph looks like this:

I wanted the years 2005 and 1995 not to appear, but 1991.

2 answers

1

Andrei,

the parameter limits serves to set the limits and not the points. For what you want to use the parameter breaks

ggplot(dados, aes(x = ano, y = k)) + geom_point() + geom_line() + scale_x_continuous(breaks = c(1991, 2000, 2010))

1

Or if x values can be taken as discrete starting:

g <- ggplot(dados, aes(x=factor(ano), y = k, group = 1))
g + geom_point() +
 geom_line() +
 labs(list(x='ano', y='k'))

inserir a descrição da imagem aqui

Browser other questions tagged

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