R: ggplot2 x axis prints as continuos, but needed as discreate -
my data:
structure(list(year = structure(1:10, .label = c("1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989" ), class = "factor"), lupas = c(1185, 822, 1340, 853, 3018, 1625, 966, 1505, 1085, 1754)), .names = c("year", "lupas"), row.names = c(na, -10l), class = c("tbl_df", "tbl", "data.frame"), drop = true)
i've group data group_by dplyr.
str(df1) classes ‘tbl_df’, ‘tbl’ , 'data.frame': 10 obs. of 2 variables: $ year : factor w/ 10 levels "1980","1981",..: 1 2 3 4 5 6 7 8 9 10 $ lupas: num 1185 822 1340 853 3018 ... - attr(*, "drop")= logi true
i'm trying plot graph of years, , "lupas" each year. time series graph.
this code, gives error:
ggplot(df1, aes(x = year, y = lupas)) + geom_line() geom_path: each group consist of 1 observation. need adjust group aesthetic?
and graph:
after reading thread: ggplot2 each group consists of 1 observation
i've changed code to:
ggplot(df1, aes(x = year, y = lupas)) + geom_line(position=position_dodge(.1))
now message:
ymax not defined: adjusting position using y instead geom_path: each group consist of 1 observation. need adjust group aesthetic?
maybe helps:
library(ggplot2) p <- ggplot(df1, aes(x = year, y = lupas, group = 1)) + geom_point(color = "black") + geom_line(color = "blue")
edit
to display specific ticks on x-axis 1 can use scale_x_discrete()
in combination breaks
:
p <- ggplot(df1, aes(x = year, y = lupas, group = 1)) + geom_point(color = "black") + geom_line(color = "blue") + scale_x_discrete(breaks = c("1980", "1985", "1989"))
Comments
Post a Comment