Last active
August 29, 2015 14:17
-
-
Save geojackass/eec66005bb1c0337f341 to your computer and use it in GitHub Desktop.
集合演算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original | |
A B | |
1 1 2 | |
2 1 3 | |
3 2 3 | |
4 3 5 | |
5 3 6 | |
# For example: | |
A B | |
1 1 5 | |
2 2 3 | |
3 3 11 | |
data <- aggregate(B ~ A, mydf, sum) | |
data | |
A B | |
1 1 5 | |
2 2 3 | |
3 3 11 | |
#output | |
write.table( data, file="data1.csv", sep=",", fileEncoding="UTF-8" ) | |
## To write a CSV file for input to Excel one might use | |
write.table( data, file = "foo.csv", sep = ",", col.names = NA) | |
#to csv | |
write.csv(d, "write.csv") | |
write.csv(d, "write.csv", quote=F, row.names=F) | |
#ggplotでoption xlim | |
m <- ggplot(data2,aes(x=data2$sio_com_count, y=data2$score1, colour=data2$resion, size=data2$total_score)) | |
m <- m + geom_point() + xlab("塩コメント数") + ylab("料理・味評価") + labs(title="塩コメント数/味評価", colour="地方別", size="総合評価") + xlim(0,150) | |
require(ggplot2) | |
d <- data.frame( | |
x = c("北海道","青森","岩手","宮城","秋田","山形","福島","茨城","栃木","群馬","埼玉","千葉","東京","神奈川","新潟","富山","石川","福井","山梨","長野","岐阜","静岡","愛知","京都","大阪","三重","滋賀","兵庫","奈良","和歌山","鳥取","島根","岡山","広島","山口","徳島","香川","愛媛","高知","福岡","佐賀","長崎","大分","熊本","宮崎","鹿児島","沖縄"), | |
y = c(3.004210526,0.744227353,1.310838446,2.253829322,1.479657388,1.193500739,1.914215686,1.138429752,1.28685259,1.488651535,1.589198036,2.132265718,4.265498398,3.414804469,1.713815789,1.661971831,1.429906542,0.683908046,1.582733813,1.269230769,1.55489022,1.489681051,1.944227552,5.274873524,6.338993329,2.270186335,2.221402214,2.650180941,3.439613527,4.339285714,2.141935484,1.272108844,2.595876289,1.958921694,1.297658863,2.575757576,0.956709957,1.193333333,0.768786127,1.001217285,0.50965251,0.4921875,0.67721519,0.614754098,0.542234332,0.419413919,1.519650655), | |
z = seq(1, 47) | |
) | |
ggplot(d, aes(x = reorder(x, z), y = y)) + | |
geom_bar(stat = "identity") + | |
xlab("都道府県") + | |
ylab("醤油スコア")+ylim(0,7) | |
require(ggplot2) | |
d <- data.frame( | |
x = c("北海道","青森","岩手","宮城","秋田","山形","福島","茨城","栃木","群馬","埼玉","千葉","東京","神奈川","新潟","富山","石川","福井","山梨","長野","岐阜","静岡","愛知","京都","大阪","三重","滋賀","兵庫","奈良","和歌山","鳥取","島根","岡山","広島","山口","徳島","香川","愛媛","高知","福岡","佐賀","長崎","大分","熊本","宮崎","鹿児島","沖縄"), | |
y = c(3.659368421,0.870337478,1.298568507,2.230853392,1.291220557,1.0605613,1.24754902,0.924586777,0.698207171,0.851802403,1.08619749,1.412811388,2.127378933,1.630819367,1.330592105,0.808450704,1.124610592,0.304597701,0.928057554,0.954907162,0.75249501,0.651969981,1.214166202,1.728499157,2.264402668,1.226708075,0.833948339,1.147165259,1.270531401,0.620535714,1.664516129,0.952380952,0.686597938,0.580231065,0.505016722,0.537878788,0.458874459,0.66,0.531791908,0.633597079,0.343629344,0.40625,0.515822785,0.473360656,0.38147139,0.412087912,1.279475983), | |
z = seq(1, 47) | |
) | |
ggplot(d, aes(x = reorder(x, z), y = y)) + | |
geom_bar(stat = "identity") + | |
xlab("都道府県") + | |
ylab("味噌スコア")+ | |
ylim(0,7) | |
require(ggplot2) | |
d <- data.frame( | |
x = c("北海道","青森","岩手","宮城","秋田","山形","福島","茨城","栃木","群馬","埼玉","千葉","東京","神奈川","新潟","富山","石川","福井","山梨","長野","岐阜","静岡","愛知","京都","大阪","三重","滋賀","兵庫","奈良","和歌山","鳥取","島根","岡山","広島","山口","徳島","香川","愛媛","高知","福岡","佐賀","長崎","大分","熊本","宮崎","鹿児島","沖縄"), | |
y = c(3.093473684,0.635879218,0.936605317,1.630196937,1.169164882,0.64844904,1.267156863,0.933884298,1.157370518,1.38317757,1.369885434,1.440094899,3.513472772,2.553538175,1.166118421,1.36056338,1.199376947,0.603448276,1.04676259,0.924403183,1.007984032,1.226078799,1.702175125,3.740303541,4.738629472,1.888198758,2.070110701,2.041013269,3.371980676,1.580357143,1.729032258,1.544217687,1.344329897,0.980744544,0.983277592,1.378787879,0.722943723,1.06,0.803468208,1.251369446,1.115830116,0.484375,0.680379747,0.717213115,0.640326975,0.485347985,1.519650655), | |
z = seq(1, 47)+ | |
) | |
ggplot(d, aes(x = reorder(x, z), y = y)) + | |
geom_bar(stat = "identity") + | |
xlab("都道府県") + | |
ylab("塩スコア")+ | |
ylim(0,7) | |
require(ggplot2) | |
d <- data.frame( | |
x = c("北海道","青森","岩手","宮城","秋田","山形","福島","茨城","栃木","群馬","埼玉","千葉","東京","神奈川","新潟","富山","石川","福井","山梨","長野","岐阜","静岡","愛知","京都","大阪","三重","滋賀","兵庫","奈良","和歌山","鳥取","島根","岡山","広島","山口","徳島","香川","愛媛","高知","福岡","佐賀","長崎","大分","熊本","宮崎","鹿児島","沖縄"), | |
y = c(1.338947368,0.378330373,0.662576687,0.979212254,0.629550321,0.274741507,0.553921569,0.662190083,0.508964143,0.773030708,1.260774686,1.4371293,3.103071415,2.686219739,0.722861842,0.704225352,1.22741433,0.672413793,0.701438849,0.921750663,0.9500998,0.967166979,1.72392638,4.286677909,4.689508793,1.540372671,2.055350554,2.53920386,3.84057971,3.825892857,0.974193548,1.129251701,1.86185567,1.376123235,1.976588629,2.598484848,0.670995671,1.043333333,0.421965318,3.444917833,2.142857143,1.375,1.303797468,1.887295082,1.348773842,1.04029304,1.88209607), | |
z = seq(1, 47) | |
) | |
ggplot(d, aes(x = reorder(x, z), y = y)) + | |
geom_bar(stat = "identity") + | |
xlab("都道府県") + | |
ylab("とんこつスコア")+ | |
ylim(0,7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment