2016-09-29 6 views
-2

나는 일련의 숫자 있다고 가정ggplot2

> dput(firstGrade_count) 
c(4L, 346L, 319L, 105L, 74L, 5L, 124L, 2L, 10L, 35L, 6L, 206L, 
7L, 8L, 6L, 9L, 26L, 1L, 35L, 18L, 4L, 4L, 2L, 63L, 6L, 23L, 
6L, 82L, 10L, 17L, 45L, 74L, 10L, 8L, 14L, 23L, 26L, 53L, 55L, 
16L, 2L, 141L, 113L, 98L, 179L, 13L, 34L, 16L, 8L, 144L, 2L, 
141L, 26L, 9L, 125L, 201L, 32L, 452L, 179L, 30L, 4L, 141L, 5L, 
40L, 7L, 255L, 120L, 223L, 28L, 252L, 21L, 8L, 362L, 4L, 5L, 
2L, 285L, 18L, 76L, 5L, 73L, 11L, 367L, 7L, 50L, 6L, 37L, 15L, 
48L, 5L, 12L, 7L, 96L) 

내가 그렇게 결과가 비슷한 것 ggplot2를 사용하여 플롯 할 :

barplot(firstGrade_count) 

ggplot2에서 미학을 어떻게 정의 할 수 있습니까? 당신은 선택적으로 쉽게 작업 할 수 있도록하고 추가를 유지하기 위해 데이터 프레임에이를 수

enter image description here

답변

1
firstGrade_count <- c(4,346,319,105,74,5,124,2,10,35,6,206,7,8,6,9,26,1,35,18,4,4,2,63,6,23,6, 
82,10,17,45,74,10,8,14,23,26,53,55,16,2,141,113,98,179,13,34,16,8,144,2,141,26,9, 
125,201,32,452,179,30,4,141,5,40,7,255,120,223,28,252,21,8,362,4,5,2,285,18,76,5,73, 
11,367,7,50,6,37,15,48,5,12,7,96) 

: 여기

내가 위에서 언급 한 기본 플롯에 의해 생성 된 플롯이다 기능은 필요하지 않지만

enter image description here

또는

library(ggplot2) 

# Optional transformation to data.frame: 
firstGrade_count <- as.data.frame(firstGrade_count) 

# Index for x-coordinates 
firstGrade_count$index <- seq(1:nrow(firstGrade_count)) 

# Plotting 
c <- ggplot(firstGrade_count, aes(index,firstGrade_count)) 
c + geom_bar(stat = "identity") 

,

firstGrade_count <- as.data.frame(firstGrade_count) 
c <- ggplot(firstGrade_count, aes(factor(firstGrade_count))) 
c + geom_bar() 

내가 그것을 설정하는 방법은 각 고유 한 값의 수를 보여줍니다. 많은 변화와 추가 형식을 추가 할 수 있습니다 : 당신이 수를 원하지 않는 경우에는 stat = 옵션을 추가하고 다른 뭔가를 기본값에서 변경할 수 있습니다

enter image description here

. 어떤 dataframe을 만들지 않고

+1

감사합니다! 그것은 매우 유익합니다! –

0

:

ggplot() + 
geom_bar(aes(1:length(firstGrade_count),firstGrade_count), stat='identity') + 
xlab('') 

enter image description here

+0

고마워,이 정확히 내가 무엇을 찾습니다 :) –