1

モバイルアプリのユーザー向けにいくつかのデータ (さまざまなバッテリーレベルごとの温度) があります。temp各ユーザーのデータ (すべて 1 行のプロット) と、すべてのユーザーの同様percentageの s の中央値 (同じグラフで、太い線を使用して強調表示) をプロットしたいと思います。ggplot2 を使用して、中央値を除くすべての線をプロットできます。これが私のダミーデータファイルです(必要に応じて、データの編成/構造を変更したり、データをグループ化したりできます):

userId, percentage, temp
11, 2, 32
11, 3, 32
11, 4, 33
11, 5, 33
11, 7, 34
11, 10, 30
12, 2, 30
12, 3, 30
12, 4, 30
12, 5, 30
12, 7, 34
12, 10, 32

現時点で私がそれを行う方法は次のとおりです。

library(ggplot2)
sampleDataFrame <- read.table(file.choose(), sep=",", header=T)
sampleDataFrame$userId <- factor(sampleDataFrame$userId)
p1 <- ggplot(sampleDataFrame, aes(x=percentage, y=temp, colour=userId)) + geom_line()
print(p1)

結果は次のとおりです。

ライン プロット

4

2 に答える 2

2

新しい変数を計算する代わりに、次を使用することもできますstat_summary

ggplot(sampleDataFrame, aes(x=percentage, y=temp, colour=factor(userId))) + 
  geom_line() + 
  stat_summary(fun.y = "median", geom = "line", color = "black", size = 1.2)

与える:

ここに画像の説明を入力

于 2016-01-10T14:53:54.987 に答える