coor_trans以在ggplot2

时间:2018-10-31 02:56:03

标签: r ggplot2

我目前正在如下进行多面可视化。

enter image description here

到目前为止一切都很好...

从更深层次上讲,我希望我可以根据贡献百分比对 X轴 Y轴进行转换...

我的意思是对于17549(alpha)小平面:

1。-45至-85之间的 X轴应该覆盖 X轴空间的3%,-85至-95可以动态覆盖11%,依此类推

2。同样,对于-3到-10之间的 Y轴,应该覆盖 Y轴范围的39%(3 + 9 + 16 + 10 + 1), -10至-14应该占42%(2 + 11 + 16 + 9 + 4)...等等

经过大量研究,在我看来,方法是建立一个适合上述变化的公式,然后创建一个trans_new。我有一个想法,因为存在离散变化,所以不可能找到适合轴的线性方程式。

我希望我能够清楚地说明问题陈述。希望能有所帮助。

...

**好吧,我将继续进行下面的详细介绍****

1。首先,我使用以下数据创建平滑线

我的数据如下

> dput(head(rqamc,4))
structure(list(sidentity = c("17549(alpha)", "17549(alpha)", 
"17549(alpha)", "17549(alpha)"), band.x = c("2300-c1", "2300-c1", 
"2300-c1", "2300-c1"), band.y = c("2300-c1", "2300-c1", "2300-c1", 
"2300-c1"), measuredSrvRsrp = c(-108, -112, -103, -118), modersrq = c(-8.75, 
-12.25, -7.75, -14.25), avgrsrq = c(-9.75, -11.25, -7.75, -13.25
), quantrsrq = c(25.65, 24, 27, 19.25), rsrqdistr = list(c(26L, 
19L, 22L, 19L, 20L, 18L, 19L, 22L, 22L, 22L, 24L, 25L, 19L, 21L, 
19L, 22L, 18L, 24L, 21L, 13L, 10L, 20L, 22L, 16L, 26L, 26L, 22L, 
22L, 21L, 14L, 21L, 22L, 12L, 7L, 21L, 21L, 21L, 21L, 25L, 25L, 
24L, 23L, 25L, 18L, 22L, 24L, 22L, 19L), c(15L, 20L, 16L, 15L, 
12L, 15L, 18L, 19L, 25L, 18L, 19L, 22L, 15L, 15L, 16L, 18L, 15L, 
20L, 20L, 25L, 15L, 22L, 22L, 10L, 10L, 22L, 20L, 20L, 21L, 18L, 
16L, 23L, 22L, 24L, 14L, 2L, 9L, 11L, 17L, 22L, 19L), c(18L, 
24L, 26L, 27L, 23L, 23L, 22L, 22L, 27L, 27L, 25L, 25L, 24L, 23L, 
25L, 23L, 22L, 25L, 24L, 19L, 27L, 27L, 26L, 26L, 27L, 23L, 25L, 
24L, 23L, 24L, 24L, 23L, 24L, 28L, 24L, 24L, 24L, 24L, 24L, 24L, 
24L, 23L, 23L, 25L, 28L, 24L, 23L, 25L, 22L, 18L), c(21L, 13L, 
15L, 11L, 12L, 16L, 10L, 11L)), meanvsmode = c(-1.4375, 2.48780487804878, 
0.0799999999999983, 2.625)), .Names = c("sidentity", "band.x", 
"band.y", "measuredSrvRsrp", "modersrq", "avgrsrq", "quantrsrq", 
"rsrqdistr", "meanvsmode"), class = c("data.table", "data.frame"
), row.names = c(NA, -4L), .internal.selfref = <pointer: 0x00000000027d0788>)

关于此数据,我将执行以下操作

g<-ggplot(data=rqamc)+geom_smooth(data=rqamc,aes(x=measuredSrvRsrp,y=as.integer(modersrq),colour=as.factor(band.x)),method = "auto",se=FALSE)+theme(legend.position = "top",legend.direction = "horizontal",axis.text.x = element_text(angle =60, hjust = 1))+scale_x_reverse(breaks=seq(-45, -140, -3),expand=c(0,0))+scale_y_reverse(breaks=seq(-3, -24, -1))+facet_wrap(sidentity~.,scale="free",ncol = 1)+ggtitle(paste0("RSRP-RSRQ Genaralized additive -Regression Model for NGBR Multicarrier Trigger Points For Circle ",mccmnc,"for ",endb[i]))

这给了我 step1

发布此信息后,我将使用以下数据绘制彩色图块和矩形

> dput(rsrprsrqtiles)
structure(list(xmin = c(-45L, -85L, -95L, -105L, -113L, -119L, 
-45L, -85L, -95L, -105L, -113L, -119L, -45L, -85L, -95L, -105L, 
-113L, -119L, -45L, -85L, -95L, -105L, -113L, -119L, -45L, -85L, 
-95L, -105L, -113L, -119L), xmax = c(-85L, -95L, -105L, -113L, 
-119L, -140L, -85L, -95L, -105L, -113L, -119L, -140L, -85L, -95L, 
-105L, -113L, -119L, -140L, -85L, -95L, -105L, -113L, -119L, 
-140L, -85L, -95L, -105L, -113L, -119L, -140L), ymin = c(-3L, 
-3L, -3L, -3L, -3L, -3L, -10L, -10L, -10L, -10L, -10L, -10L, 
-14L, -14L, -14L, -14L, -14L, -14L, -17L, -17L, -17L, -17L, -17L, 
-17L, -19L, -19L, -19L, -19L, -19L, -19L), ymax = c(-10L, -10L, 
-10L, -10L, -10L, -10L, -14L, -14L, -14L, -14L, -14L, -14L, -17L, 
-17L, -17L, -17L, -17L, -17L, -19L, -19L, -19L, -19L, -19L, -19L, 
-24L, -24L, -24L, -24L, -24L, -24L), tilecolor = c("green", "lightgreen", 
"yellow", "orange", "red", "red", "lightgreen", "lightgreen", 
"lightgreen", "lightgreen", "lightgreen", "lightgreen", "red", 
"red", "red", "orange", "orange", "orange", "red", "red", "red", 
"red", "red", "red", "red", "red", "red", "red", "red", "red"
), category = 1:30), .Names = c("xmin", "xmax", "ymin", "ymax", 
"tilecolor", "category"), row.names = c(NA, -30L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x00000000027d0788>)

和以下代码

tilecreation<-geom_rect(data=rsrprsrqtiles,aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,fill=tilecolor),alpha=0.2,colour="blue")

g1<-g+tilecreation+scale_fill_manual(values=c("green"="green","red"="red","yellow"="yellow","lightgreen"="lightgreen","orange"="orange"))

生产

step2

此后,我按如下注释每个类别矩形

该数据

> dput(head(rqascales,4))
structure(list(sidentity = c("17549(alpha)", "17549(beta)", "17549(gamma)", 
"17549(alpha)"), category = c(1L, 1L, 1L, 2L), bandcomb = c("2300-c1/2300-c2/1800-c1/850-c1", 
"2300-c1/2300-c2/1800-c1/850-c1", "2300-c1/2300-c2/1800-c1/850-c1", 
"2300-c1/2300-c2/1800-c1/850-c1"), totalsample = c(52066L, 151251L, 
90452L, 52066L), persecpercategorysample = c(1404L, 372L, 1204L, 
4515L), persecperbandpercategorysample = list(c(260L, 213L, 78L, 
853L), c(97L, 46L, 41L, 188L), c(135L, 30L, 7L, 1032L), c(659L, 
696L, 251L, 2909L)), pccattothesector = c(3, 0, 1, 9), pcbandtothecategory = list(
    c(19, 15, 6, 61), c(26, 12, 11, 51), c(11, 2, 1, 86), c(15, 
    15, 6, 64)), tilecolor = c("green", "green", "green", "lightgreen"
), xpoint = c(-47, -47, -47, -87), ypoint = c(-6.5, -6.5, -6.5, 
-6.5), bandcontri = c("19,15,6,61", "26,12,11,51", "11,2,1,86", 
"15,15,6,64"), bandcontriab = c("2.6 h-2.1 h-78 -8.5 h", "97 -46 -41 -1.9 h", 
"1.4 h-30 -7 -1 K", "6.6 h-7 h-2.5 h-2.9 K")), .Names = c("sidentity", 
"category", "bandcomb", "totalsample", "persecpercategorysample", 
"persecperbandpercategorysample", "pccattothesector", "pcbandtothecategory", 
"tilecolor", "xpoint", "ypoint", "bandcontri", "bandcontriab"
), class = c("data.table", "data.frame"), row.names = c(NA, -4L
), .internal.selfref = <pointer: 0x00000000027d0788>)

和代码

g1<-g1+geom_text(data=rqascales,aes(x=xpoint,y=ypoint,label=paste0(formatter(pccattothesector),"%"),size=pccattothesector))+scale_size(range = c(4,8))

产生最终输出

the final one

我想要的是。划定x轴和y轴的分界 与贡献百分比成比例...

例如 因为x轴的第一个分界是-85 ..对于17549α的第一个小平面,我需要使这条线位于x轴跨度的3%(3 + 0 + 0)上。我希望-45至-85的范围跨越x轴长度的3%...范围-85至-95的范围跨越11%(9%+ 2%+ 0%)..范围-95至-105范围为28%(16%+ 11%+ 1%+ 0%)....等等。

y轴也一样。

我正在尝试找出如何完成coord_trans ..或其他操作

希望我能够正确阐述。 感谢您的关注

0 个答案:

没有答案