使用 facet_grid 时如何使 geom_rect 具有一致的阴影?

如何解决使用 facet_grid 时如何使 geom_rect 具有一致的阴影?

这是我正在处理的数据:

df= structure(list(effect = c(-0.183660494380325,-0.286711283030125,0.144420824373155,0.107958002095135,-0.236028784063033,-0.160120624560128,-0.241734940173219,-0.301094909534684,0.080319901278758,0.166386486331364,2.18044670333557,0.150214406648656,0.101218219003822,-0.382893498692355,-0.131525337511054,-0.0963503379451771,-0.266851983630642,-0.237371391841929,-0.0718562471672148,-0.833148477215979,-0.31532073921026,-0.666010175452128,0.128074208388128,0.105220228400002,0.212888583788477,0.173837214351567,0.0723268793073809,0.227657131980834,0.219566925261995,-0.0577587298548685),lower = c(-0.378799556647341,-0.758072446650849,0.0273385116378299,-0.0239857116078122,-0.595394742028366,-0.392378190445114,-1.07812282304258,-0.870284236088555,-0.117427834790597,0.0202865790073198,-0.0309968796929358,-0.115160638753749,-0.0518695893701463,-1.77050833334992,-0.413234955839275,-0.715635813448282,-0.731134011308218,-0.688660305462684,-0.743460375678667,-1.87822726521072,-1.69792593382383,-2.31272677544801,-0.028273151895772,-0.247721998059409,-0.0799161658359572,-0.110588127178339,-0.114331814482118,-0.127583669808567,-0.114524635314751,-0.393815864368995
),upper = c(0.0119292041841525,0.188761936680526,0.261375601855666,0.239780243784321,0.125309603839398,0.0726943910130132,0.606383207664197,0.274457379488013,0.277860600000933,0.31225850014966,4.28541221179007,0.414903371934528,0.254152061126853,1.06207219690377,0.150862559742933,0.525447262952953,0.201162598075368,0.217070141774486,0.601971540143289,0.260535057064083,1.11526641785088,1.10904764279685,0.284217288085084,0.457299344432491,0.504523841925775,0.45735105097433,0.258818976847914,0.58105825758076,0.552088686400803,0.278729034684897),Subject = structure(c(1L,2L,3L,4L,1L,4L),.Label = c("BIOL112_2019W1","CHEM100_2019W1","CHEM121_2019W1","PHYS100_2019W1"),class = "factor"),item = c("Anx","Anx","Anx"),Dem = c("All","All","Man","Woman","Non-binary","On-campus","<30 min","<60 min",">60 min",">60 min"),cat = c("Class","Class","Gender","Commute","Commute"
    )),row.names = c(NA,-30L),class = "data.frame")

当我绘制 facet_grid ggplot 对象并将矩形添加到 alpha = 0.2 的图时,当我的矩形有不同的 alpha 值时,我的矩形具有不同的 alpha 值。我不明白为什么:

ggplot(df,aes(x=Dem) )+
      theme_bw()+
      geom_rect(aes(ymin = 0,ymax = 0.2,xmin = -Inf,xmax = Inf,fill = 'negligible'),alpha = .2)+
      geom_rect(aes(ymin = 0.2,ymax = 0.5,fill = 'small'),alpha = .2)+
      geom_rect(aes(ymin = 0.5,ymax = 0.8,fill = 'medium'),alpha = .2)+
       geom_rect(aes(ymin = 0.8,ymax = Inf,fill = 'large'),alpha = .2)+
      geom_rect(aes(ymin = 0,ymax = -0.2,alpha = .2)+
      geom_rect(aes(ymin = -0.2,ymax = -0.5,alpha = .2)+
      geom_rect(aes(ymin = -0.5,ymax = -0.8,alpha = .2)+
       geom_rect(aes(ymin = -0.8,ymax = -Inf,alpha = .2)+
         geom_point(aes(y=effect),stat="identity")+
      #scale_x_discrete(position = "top") +
      geom_errorbar(aes(ymin=lower,ymax=upper),width=.2)+
      facet_grid(Subject~cat,scales="free")+ 
      theme(axis.text.x = element_text(angle = 45,hjust = 1))

enter image description here

我希望所有矩形的 alpha 一致为 0.2,因此对于每个分面图,它们看起来都相同

解决方法

问题是过度绘制。您添加 public static void main(String args[])throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Hi,I am a calculator"); System.out.println("As your real life calculator,I can do the same things"); System.out.println("But I can only operate on 2 numbers,one at a time"); System.out.println("And for every other operation,you have to exit and come back to the terminal window"); System.out.println("But there are some other useful operations available here as well"); boolean shouldContinue; do { System.out.println("So now,give me any 2 numbers on which you want me to operate"); double n1=Double.parseDouble(in.readLine()); double n2=Double.parseDouble(in.readLine()); calculator ob=new calculator(); System.out.println("What you want to do with these 2 numbers [give the number in the list below which correspons to that operation]"); System.out.println("1=> Addition"); System.out.println("2=> Subtraction"); System.out.println("3=> Multiplication"); System.out.println("4=> Division"); System.out.println("5=> Find the remainder of their division"); System.out.println("6=> Find the percentage of one to the other"); System.out.println("7=> Find the power of the 1st number to the 2nd number"); System.out.println("8=> Find the square root of anyone of the numbers"); System.out.println("9=> Find the cube root of anyone of the numbers"); int p=Integer.parseInt(in.readLine()); switch(p) { case 1: ob.add(n1,n2); break; case 2: ob.subtract(n1,n2); break; case 3: ob.multiply(n1,n2); break; case 4: ob.divide(n1,n2); break; case 5: ob.findremainder(n1,n2); break; case 6: ob.percent(n1,n2); break; case 7: ob.power(n1,n2); break; case 8: ob.squareroot(n1,n2); break; case 9: ob.cuberoot(n1,n2); break; default: System.out.println("Provided op-code not supported!"); } System.out.println("Do you want to continue? (yes/no)"); String choice = in.readLine(); shouldContinue=choice.equalsIgnoreCase("yes"); } while(shouldContinue); System.out.println("So I hope you got your answer and you are satisfied with it"); System.out.println("Also,please give a feedback to my master"); System.out.println("Your feedback could help me to improve more and more"); System.out.println("And if I got time... I could conqueror the world"); System.out.println("Anyways..."); System.out.println("Thank you for accessing me and I hope you have a great day"); } 的方式意味着为每个 (!!) 观察或数据行绘制一个矩形,即多个矩形绘制在彼此的顶部。由于观察的数量因方面而异

  1. 每个方面绘制的矩形数量各不相同
  2. 每个面都有不同的阴影,即观察越多,阴影越暗。

要解决您的问题,请制作一个包含矩形坐标的数据框,它还允许通过一个 geom_rect 添加它们。

geom_rect

reprex package (v2.0.0) 于 2021 年 6 月 7 日创建

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-