私はプロットしたい点を持つデータシートを2つ持っています(最初のデータセットの各ポイントは異なる測定値の平均です)各点の偏差。2つのテーブルから来るデータのためのErrobarを持つ複数のラインプロット
以下は、うまく動作する最初のデータからlineplotを作成するためのRスクリプトを添付しました。コードで、私は今、私は以前同様のプロットを作成するために、第2のテーブル(標準偏差)を使用したいが、今も、エラーバーを示す、すなわち、以下のことを
のようなプロットを作成することができますthisのような各測定の標準偏差をグラフィカルに表示します。
library(ggplot2)
##loads a dataframe and returns a ggplot object that can be externally modified and plotted
makeMultipleLinePlot <- function(data){
require(reshape2)
data$id <-rownames(data)
melted <- melt(data)
colnames(melted)<-c("Measurement","Month","Percentage")
g<-ggplot(data=melted,
aes(x=Month, y=Percentage, color=Measurement,group=Measurement)) +
geom_line(size=1,alpha=0.8) + geom_point(size=4,aes(shape=Measurement))
return(g)
}
##load a table from google sheets. assumes the sheet has a single table
loadTableFromGoogleSheet <- function(url, sheet) {
require(gsheet)
a <- gsheet2text(url,sheetid=sheet, format='csv')
data <- read.csv(text=a, stringsAsFactors=FALSE,header = TRUE,row.names = 1)
return(data)
}
#URL of the google spreadsheet
url <- "docs.google.com/spreadsheets/d/10clnt9isJp_8Sr7A8ejhKEZXCQ279wGP4sdygsit1LQ"
gid.humidity <- 2080295295 #gid of the google sheet containing humidity data
data.humidity<-loadTableFromGoogleSheet(url,gid.humidity)
gid.humidity_sd <- 1568896731 #gid of the google sheet containing standard deviations for each measurement in the humidity data
data.humidity_sd<-loadTableFromGoogleSheet(url,gid.humidity_sd)
ggsave(filename="lineplot/humidity.pdf", plot=makeMultipleLinePlot(data.humidity))
#ggsave(filename="lineplot/humidity.pdf", plot=makeMultipleErrorPlot(data.humidity,data.humidity_sd))
がhttp://docs.ggplot2.org/0.9.3.1/geom_errorbar見ます.htmlあなたは 'geom_errorbar(data = data2、aes(x、sd)) 'を使ってエラーバーをポイントに追加することができます。 –