Reputation: 9103
I have this Data.Frame
(mydf
):
year total
1999 3967
2002 580
2005 5203
2008 2406
and to display it, I just run:
plot(mydf)
However I can see on the x-axis (year
) the labels:
2000 2002 2004 2006 2008
How can I tell to plot/axis
to display only the four expected values: 1999,2002,2005,2008
without trying to infer the sequence?
Upvotes: 1
Views: 80
Reputation: 887098
If we are using ggplot
, we can also try
library(ggplot2)
library(dplyr)
mydf %>%
mutate(year = as.character(year)) %>%
ggplot(., aes(x=year, y = total)) +
geom_point() +
scale_x_discrete(labels = mydf$year) +
theme_bw()
mydf <- structure(list(year = c(1999L, 2002L, 2005L, 2008L), total = c(3967L,
580L, 5203L, 2406L)), .Names = c("year", "total"), class = "data.frame", row.names = c(NA,
-4L))
Upvotes: 2
Reputation: 73285
As akrun suggest, you can use:
plot(mydf, xaxt = "n")
axis(1, at = mydf$year)
Data:
mydf <- structure(list(year = c(1999L, 2002L, 2005L, 2008L), total = c(3967L,
580L, 5203L, 2406L)), .Names = c("year", "total"), class = "data.frame",
row.names = c(NA, -4L))
Upvotes: 2