我正在處理一些相當精細的一些室內和室外活動情節,而我有點卡住了。我想在我的情節的geom_segment
步驟中添加(Xmin
,Ymin
和Zmin
)在室內/室外花費的分鐘數(參見下文)。目前僅有着色Zmin
(使用一個連續變量,這是有點關閉)。ggplot2,geom_segment的顏色段
我粘貼了所有的代碼,以防其他人想要構建類似的東西,我最初的啓發是this blog post。
任何幫助將不勝感激,謝謝!
df <- data.frame(
date = seq(Sys.Date(), len= 156, by="4 day")[sample(156, 26)],
action = paste('Then', LETTERS[1:13], 'happed, which was not related to', LETTERS[14:26]),
IndoorOutdoor = rep(c(-1,1), 13),
Xmin = sample(90, 26, replace = T),
Ymin = sample(90, 26, replace = T),
Zmin = sample(90, 26, replace = T)
)
df$XYZmin <- rowSums(df[,c("Xmin", "Ymin", "Zmin")])*df$IndoorOutdoor
# install.packages("ggplot2", dependencies = TRUE)
require(ggplot2)
# step 1
plot <- ggplot(df,aes(x=date,y=0))
# step 2, this is where I want to add 'more' color
plot <- plot + geom_segment(aes(y=0,yend=XYZmin,xend=date, colour= Zmin))
# The text is added as follows
plot <- plot + geom_text(aes(y=XYZmin,label=paste(action, '\n this happed on ', date)),size=2.5,hjust=-.01, vjust=-.01, angle = 35)
# points at the end of the line segments
plot <- plot + geom_point(aes(y=XYZmin))
# #raw a vertical line
plot <- plot + geom_hline(y=0,size=1,color='purple')
#drawing the actual arrow
# plot <- plot + geom_segment(x=2011.4,xend=2012.2,y=.2,yend=0,color='purple',size=1) + geom_segment(x=2011.4,xend=2012.2,y=-.2,yend=0,color='purple',size=1)
plot <- plot + theme(axis.text.y = element_blank()) + ylab('') + xlab('')
plot + labs(title = "Timeline for when what happened")
「Zmin」映射作爲一個連續變量以可定義的方式着色。你想如何將三個數字映射到單一色階?如果它們是離散的,我可以看到一個映射到它們之間的相互作用,但是這對連續變量沒有意義。 – 2013-03-11 23:32:46
@BrianDiggs,謝謝你回覆我的問題。這是我的表述不準確。我設想了一個獨立版本的'Xmin','Ymin'和'Zmin',並用三種不同的顏色將各個部分着色。那有意義嗎? – 2013-03-11 23:37:57
@BrianDiggs,像[這些細分市場](http://i.stack.imgur.com/78BKj.png)或像[此行](http://3.bp.blogspot.com/-N7UsdR5vws8/T9Ezi4MQU4I/ AAAAAAAAAA8/oNq1iNZtq0E/S1600/lineWithDifferentColorsAndSize.JPG)。請讓我知道這是否回答你的問題。如果不是,我很樂意嘗試在我的情節中說明它。 – 2013-03-11 23:41:18