2016-09-29 5 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) 

オプションで、それが簡単で動作するようにするために、データフレームにこれを行うことができますし、追加を保持します機能は必須ではありませんが、

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") 

enter image description here

あるいは、

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

私はそれを設定する方法は、あなたにそれぞれユニークな値の数を示します。

enter image description here

をあなたがstat =オプションを追加し、何か他のものにデフォルトから変更することができ、カウントをしたくない場合は:あなたが追加することができ、多くのバリエーションや追加のフォーマットがあります。すべてのデータフレームを作成せずに

+1

ありがとうございます!それは非常に有益です! –

0

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

enter image description here

+0

ありがとう、これはまさに私が探しているものです:) –