码迷,mamicode.com
首页 > 其他好文 > 详细

ggtheme主题学习

时间:2016-05-11 23:48:53      阅读:601      评论:0      收藏:0      [点我收藏+]

标签:

 
数据文件:
技术分享
 
 
 
  1. #构造数据。
  2. #datahs300.csv中存放的是时间和沪深300指数的对数收益率
  3. index300<-read.csv("datahs300.csv",header=T)
  4.  
  5. #查看数据
  6. head(index300)
  7. #通过一个循环,构造一个标识列
  8. #对数收益率为正的,tagp值取作0
  9. #对数收益率为正的,tagp值取作1
  10. #将收益率转化为百分比
  11.  
  12. for(i in 1:length(index300[,2])){
  13.   if(index300[,2][i]<0){
  14.     index300$tagp[i]<-1
  15.   }
  16.   else{
  17.     index300$tagp[i]<-0
  18.   }
  19.   index300$lgreturn[i]<-index300$lgreturn[i]*100
  20. }
  21.  
  22. #查看数据
  23. head(index300)
    1. TIME lgreturn tagp
    2. 12015/01/053.00583590
    3. 22015/01/06-0.01318211
    4. 32015/01/070.07495010
    5. 42015/01/08-2.34716911
    6. 52015/01/09-0.35294251
    7. 62015/01/12-0.93877721
     
 
加上geom_point()就是画散点图。
aes中的colour = factor(tagp),是设定按照tagp转换为因子后分类配色
  1. #导包
  2. library(ggplot2)
  3. library(ggthemes)
  4.  
  5. #制作散点图
  6. testp<- ggplot(index300, 
  7.                aes(x =as.Date(TIME), 
  8.                    y = lgreturn, 
  9.                    colour = factor(tagp)))+
  10.  
  11.         geom_point()
  12. testp
  13. 技术分享
 
  1. testp+theme_solarized_2()
  2. 技术分享
 
 
  1. testp+theme_solarized(light = FALSE)
  2. 技术分享
  3.  
  4.  
  5. testp+theme_solarized(light = FALSE)+
  6.       scale_colour_solarized("blue")
  7. 技术分享
  8.  
  9. testp+ theme_solarized_2(light = FALSE) + scale_colour_solarized("blue")
  10. 技术分享
 
  1. testp+theme_economist()+
  2.       scale_colour_economist() 
  3. 技术分享
 
 
  1. testp+geom_point()+
  2.  
  3.   theme_solarized(light = FALSE)+
  4.  
  5.   scale_colour_solarized("blue")+
  6.  
  7.   geom_smooth(method ="loess")
  8. 添加趋势线(lm/glm/gam/loess)
  9. 技术分享
 
  1. testp + ggtitle("logreturn")+ 
  2.         theme_wsj()+ 
  3.         scale_colour_wsj("colors6","")
  4. 技术分享
 
 
 
 
 
 
 
 
 
 
 
 





附件列表

 

ggtheme主题学习

标签:

原文地址:http://www.cnblogs.com/xuanlvshu/p/5483945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!