2017-05-12 1 views
1

나는이 같은 dataframe이 Barplot : 내가 사용 barplot를 만들기 위해 노력하고일년 내내 표시되지 않습니다 연간 볼륨

x <- structure(list(year = structure(c(2008,2009,2010,2011,2012,2013,2014,2015,2016,2017)), value = c(0,11,20,31,1000,10,500,161,20,3)), .Names = c("year", "value"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame") 

을이 :

library(ggplot2) 
ggplot(x, aes(year, value, fill=year)) + 
    geom_bar(stat="identity", position="dodge") 

내 문제

은 다음과 같습니다 x 축은 연도가 2007 년 5 일인이 형식을 가지고 있습니다 (그들은 .5 월이 있지만 나는 1 년 밖에 갖고 싶지 않습니다). 2008 년부터 1 년 내내 x 축에 있고 2 년마다가 아닌 모든 연도를보고 싶습니다.

문제를 해결할 수있는 방법이 있습니까?

답변

2

yearnumeric이므로 수치 축이 생성됩니다.

당신은 당신은 scale_x_continuous 이산 휴식 값을 부과 할 수 as.character(year)

ggplot(x, aes(as.character(year), value, fill=year)) + 
geom_bar(stat="identity", position="dodge") 
2

year을 대체하여이 문제를 해결할 수 있습니다

ggplot(x, aes(year, value)) + 
    geom_bar(stat="identity", position="dodge") + 
    scale_x_continuous(breaks=2008:2017) 

enter image description here

관련 문제