R语言绘图

R语言的可视化完整版
https://wenku.baidu.com/view/ea6a948ca300a6c30c229f96.html

install.packages('devtools')
require(devtools)
devtools::install_github('taiyun/recharts')

在Rstuido中图片可以预览 在R中自动生成html 可以download保存

library(recharts)

df2 = data.frame(
  saleNum=c(10,20,30,40,50,60,70,15,25,35,45,55,65,75,25,35,45,55,65,75,85),
  seller=c(rep("小黄",7), rep("小红",7), rep("小白",7)),
  weekDay = c(rep(c("周一","周二","周三","周四","周五","周六","周日"),3))
)
eBar(dat= df2, xvar=~weekDay, yvar=~saleNum, series=~seller)
#png(file="myplot.png", bg="transparent")  无效

ggplot柱状图
http://blog.csdn.net/bone_ace/article/details/47267981
标尺 颜色 坐标轴等
http://blog.sina.com.cn/s/blog_69ffa1f90101sigb.html

挑战不可能之——ggplot环形字体地图
http://www.sohu.com/a/133110897_572440

各种条形图 以及主题

https://zhuanlan.zhihu.com/p/27316157
ggplot2——主题篇

圆弧条形图

http://blog.csdn.net/scutshuxue/article/details/8836848
country<-c("老挝","菲律宾","尼泊尔","孟加拉","阿富汗","新加坡","泰国","蒙古","新西兰","印度尼西亚","印度","澳大利亚","台湾","日本","香港","柬埔寨","马来西亚","巴基斯坦","韩国","斯里兰卡","中国","越南")  
percent<-c(90,81,80,77,75,74,73,72,68,68,68,67,65,63,61,60,59,58,53,51,49,48)  
d<-data.frame(country,percent)  
png("d:\\test.png",width = 2048, height = 2048)  
f<-function(name,value){  
      
    xsize=200  
    plot(0, 0,xlab="",ylab="",axes=FALSE,xlim=c(-xsize,xsize),ylim=c(-xsize,xsize))  
    for(i in 1:length(name)){  
        info = name[i]  
        percent = value[i]  
        k = (1:(360*percent/100)*10)/10  
        r=xsize*(length(name)-i+1)/length(name)  
        #print(r)  
        x=r*sin(k/180*pi)  
        y=r*cos(k/180*pi)  
        text(-18,r,info,pos=2,cex=3)  
        text(-9,r,paste(percent,"%"),cex=3)  
        lines(x,y,col="red")  
    }  
}  
  
#用R打开,图片在文件中显示正常 R中不正常  
f(country,percent)  
dev.off()


#7个一组
dd<-read.table("clipboard",header=TRUE)
class(dd$percent[1])
class(d$percent[1])
dd$percent<-as.numeric(dd$percent)
length(index)

png("d:\\test1.png",width = 2048, height = 2048)  
f<-function(name,value){  
  
  xsize=800  
  plot(0, 0,xlab="",ylab="",axes=FALSE,xlim=c(-xsize,xsize),ylim=c(-xsize,xsize))  
  # color<-c("red","green","purple","black","yellow","blue","red","green","purple","black","yellow","red","green","purple","black","yellow","red","green","purple","black","yellow","blue")

  a<-rep(rainbow(5,alpha=0.5),c(7,7,7,7,7))

  for(i in 1:length(name)){  
    info = name[i]  
    percent = value[i]  
    k = (1:(360*percent/100)*10)/10
    r=xsize*(length(name)-i+1)/length(name)
    #print(r)  
    x=r*sin(k/180*pi) 
    y=r*cos(k/180*pi)  
    text(-80,r,info,pos=2,cex=2.5)  
    text(-27,r,paste(percent,"%"),cex=2.5)  
    lines(x,y,col=a[i],lwd=10,type="l")
  }  
}  

f(dd$index,dd$percent)  
dev.off() 

地图
ggmap
https://cos.name/2013/01/drawing-map-in-r-era/
http://www.dataguru.cn/article-3381-1.html

REmap
http://blog.csdn.net/yc_1993/article/details/51407981
通过REmap包画航线图
http://jingyan.baidu.com/article/5d6edee2eff2c599ebdeec7e.html
用R语言绘制动态地图,代码奉上!(REmap包详解)

直方图重叠overlapping
http://www.iqiyi.com/w_19rspw1ech.html
hist(aim0$sum,xlim=c(-10,110),ylim=c(0,1300),main="score of unsatisfy vs satisfy",xlab="score",ylab=" Number",col=rgb(1,0,0,0.5))
hist(aim1$sum,add=TRUE,col=rgb(0,1,0,0.5))
R语言可视化——图表嵌套(母子图)
https://zhuanlan.zhihu.com/p/27242202
ggplot2  以diamonds为例
https://www.plob.org/article/7264.html
plt.style.use('ggplot')
plt.plot(data_num1['date_string'],data_num1['U22'],'bo:',label='U22_0')
plt.plot(data1_1['date_string'],data1_1['U22'],'m*:',label='U22_1')

plt.legend()

#fill的用法
####修正因子水平 横轴标签顺序
mydata2$Name=factor(mydata2$Name, levels=as.vector(data_barplot$Name))
mydata2$class=1

cs=c('C7','C30','C44','C45','C33')
Service_access=c('U9','U6','U4','U7')
Service_quality=c('U14','U12','U22')
net_access=c('C3','C2','C27','C41','C29','C12','C40')
net_keep=c('C25','C23','C26','C54','C56','C9','C18')

for (i in 1:26){
  myname=mydata2$Name[i]
  mydata2$class[i]=ifelse(myname %in% cs,'语音接入性',ifelse(myname %in% Service_access,'业务接入性',ifelse(myname %in% Service_quality,'业务质量',ifelse(myname %in% net_access,'网络接入性','网络保持性'))))
}

#屏幕取色 colorpix
#调色板定制
cbbPalette <- c("#C23531", "#2F4554", "#61A0A8", "#D48265", "#9CC5B2") 

ggplot(mydata2,aes(Name,Score,fill=class))+
  geom_bar(stat="identity",position="dodge")+
  labs(x="index",y='Relative score')++scale_fill_manual(values=cbbPalette) 


你可能感兴趣的:(R语言绘图)