[問題] ggplot 資料問題
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
入門(寫過其他程式,只是對語法不熟悉)
[問題敘述]:
我有一筆資料,想用ggplot畫成時間序列的圖
畫出來後,分成男女性別再畫一次
結果出現 "錯誤: Aesthetics must be either length 1 or the same as the data "
google之後還是不太清楚原因
[程式範例]:
有四個變數no,sex,time,type type的值只有1跟4
head(data)
no sex time type
12094851 2 2015-10-18 1
12094851 2 2016-04-15 1
12094851 2 2016-07-14 1
12024856 2 2016-01-19 1
:
:
10567401 1 2015-12-20 4
11339563 1 2016-04-03 4
11255465 1 2015-12-12 4
31444461 2 2015-09-03 4
ggplot(data,aes(y=factor(no),x=time))+
geom_point(shape=type,size=1.7,colour=sex)+
geom_line()
畫出來是這樣 https://i.imgur.com/pOwgrDr.png

data_men<-data[data$sex==1,] 之後把男性的資料分離出來再做一次
ggplot(data=data_men,aes(y=factor(no),x=time))+
geom_point(shape=type)+
geom_line()
錯誤: Aesthetics must be either length 1 or the same as the data (162): shape
如果把shape移到aes()裡面是可以執行 但線的位置會跑掉
ggplot(data=data_men,aes(y=factor(no),x=time,shape=factor(type)))+
geom_point()+
geom_line()
https://i.imgur.com/kJUlJ23.png

想知道錯誤訊息原因 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.164.162.242
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1514380572.A.765.html
→
12/28 12:06,
7年前
, 1F
12/28 12:06, 1F
→
12/28 12:09,
7年前
, 2F
12/28 12:09, 2F
→
12/28 12:10,
7年前
, 3F
12/28 12:10, 3F
→
12/28 12:11,
7年前
, 4F
12/28 12:11, 4F
→
12/28 21:28,
7年前
, 5F
12/28 21:28, 5F
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章
84
220