2

かなり時間がかかるため、分割したくない大きなデータセットがあります。1 つの列には、各プロットが別の場所に属しているため、個別のプロットを作成したい公園のリストが含まれています。各公園は、時系列グラフとしてゾーンと年でグループ化する必要があります。Height_mm の平均も標準誤差で計算する必要があります。それぞれ 3 つの異なるゾーンと 10 の異なる年を持つ 5 つの異なる公園があります。csv には 5000 を超えるレコードがあります。

head(data)

  Park_name  Zone Year  Height_mm
1     Park1 Zone1 2011        380
2     Park1 Zone1 2011        510
3     Park1 Zone1 2011        270
4     Park1 Zone2 2011        270
5     Park1 Zone2 2011        230
6     Park1 Zone2 2011        330

私はそれを理解することはできませんが、以下のコードを操作してこれを機能させたいと思っています。ただし、他の提案があれば喜んで受け入れます。

library(ggplot2)
library(plyr)

data=read.table("C:/data.csv", sep=",", header=TRUE)

ggplot(data, aes(x=Year, y=Height_mm)) + 
  #geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.05, colour="black", position=pd) +
  geom_line() +
  geom_point(size=3, fill="black") +
  xlab("Year") + 
  ylab("Mean height (mm)") +
  #facet_wrap(~Park_name, scales = "free", ncol=2) + #I'd like something like this but with all plots as separate figures
  theme_bw() +
  theme(axis.text.x=theme_text(),  
        #axis.title.x=theme_blank(), 
        #axis.title.y=theme_blank(), 
        axis.line=theme_segment(colour="black"), 
        panel.grid.minor = theme_blank(),
        panel.grid.major = theme_blank(),
        panel.border=theme_blank(),
        panel.background=theme_blank(),
        legend.justification=c(10,10), legend.position=c(10,10), 
        legend.title = theme_text(),
        legend.key = theme_blank()
  )

どこに置くか、またはどのように使用するかはわかりませんが、ある種の「for」ループが必要だと思います。ありがとう

4

1 に答える 1

1

次のようなことをしたいようです。あなたの質問を誤解した場合は、質問を修正してください。複数の公園、ゾーン、年からのデータを提供することもできます。

# load packages
require(ggplot2)
require(plyr)
# read data 
Y <- read.table("C:/data.csv", sep=",", header=TRUE)
# define the theme
th <- theme_bw() +
  theme(axis.text.x=element_text(),  
        axis.line=element_line(colour="black"), 
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.background=element_blank(),
        legend.justification=c(10,10), legend.position=c(10,10), 
        legend.title = element_text(),
        legend.key = element_blank()
        )
# determine park levels
parks <- levels(Y[,"Park_name"])
# apply seperately for each park
p <- lapply(parks, function(park) {
ggplot(Y[Y[, "Park_name"]==park,], aes(x=as.factor(Year), y=Height_mm)) +
  facet_grid(Zone~.) + # show each zone in a seperate facet
  geom_point() + # plot the actual heights (if desired)
  # plot the mean and confidence interval
  stat_summary(fun.data="mean_cl_boot", color="red") 
})       
# finally print your plots
lapply(p, function(x) print(x+th))
于 2013-07-26T09:08:59.093 に答える