control series line colors and

I am using ggplot2 to plot a time series of sensor data (however I have found it impossible to manipulate the x-axis to show the time in a readable format).

The data frame I am using is in the form of

> head(df)
    timeCol  dataCol ToolFactor     Delta    Chuck   Tool
1 1/5/2016 0:02 63.90383 1_A            0.000000 A       1
2 1/5/2016 0:02 63.58735 1_A           -0.316475 A       1
3 1/5/2016 0:03 64.45610 1_A            0.868747 A       1
4 1/5/2016 0:03 64.25554 1_A           -0.200561 A       1
5 1/5/2016 0:04 64.24784 1_A           -0.007698 A       1
6 1/5/2016 0:04 64.01986 1_A           -0.227982 A       1

Where factor is a combination of chuck and tool where tool goes from 1-15 and each tool has A and B chuck

The below code plots two series on a geom_line() A and B data for a given tool(already segmented by tool at this point):

p2 = ggplot(df,aes(timeCol,Delta)) +  
  labs(x="Past 7 days of Data Points",y="Point to Point") +  
  theme(axis.text.x = element_blank(),legend.position="none",plot.margin=unit(c(1,1,1,1),"cm"),panel.grid.major = element_line(colour = "white", size=2)) + 
  geom_line() + 
  ggtitle(paste("Point to Point Per Chuck M",tool,sep = "" )) + 
  geom_hline(yintercept=c(-5,-2,2,5),linetype=2,color="red") +  
  scale_y_continuous(limits=c(-7.5,7.5)) + 
  geom_text(aes(label=ifelse(abs(Delta)>4,as.character(timeCol),'')),hjust=0.5,vjust=-1.5,size=2)

p2 + scale_color_manual(values=c("#CB6326", "#086E8B"))

My issue is by setting the aesthetic in the ggplot() phase I can get the plot to show each chuck(factor) individually but then I need to live with the standard light green and red colors it sets as standard.

If someone could show me how I can control line/plot area/point colors of each individual series I would be very grateful. Also I can get this to display properly sometimes, but when I create a html report with knitr it displays both series in black - any ideas why this isn't working?

链接地址: http://www.djcxy.com/p/86154.html

上一篇: 子集和ggplot2

下一篇: 控制系列线的颜色和