本文介绍了scale_y_log10()和coord_trans(ytrans ='log10')导致不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用日志转换进行统计分析(反应时间),现在我想绘制我的数据,并将日志转换为y轴。当我使用coord_trans(ytrans =log10)给我正确的结果 - 但我需要酒吧而不是点我的图。 当我使用scale_y_log10()时,它可以和小节一起工作,但它会绘制错误的值(bar1的平均值为833,但显示在900以上; bar2的平均值为568,但显示接近500) set.seed(10) bar1 graph_data< - data.frame (RT = c(bar1,bar2),group = c(rep(1,232),rep(2,393))) ggplot(graph_data,aes(group,RT))+ stat_summary(fun.y = mean,geom ='point',position ='dodge')+ stat_summary(fun.data = mean_cl_normal,geom ='pointrange',position ='position_dodge'(width = .9))+ coord_trans(ytrans =log10) ggplot(graph_data,aes(group,RT))+ stat_summary(fun.y = mean,geom ='bar',position ='dodge')+ stat_summary(fun.data = mean_cl_normal,geom ='pointrange',position ='position_dodge'(width = .9))+ scale_y_log10 = seq(3 00,1000,100)) 感谢您的帮助! 首先,如果您将看到帮助页面 coord_trans()您会看到: coord_trans与缩放转换不同因为它在统计转换后出现,并且会影响几何形状的视觉外观 - 不能保证直线会继续到直线。 这意味着使用 coord_trans()时,只有坐标(y轴)会受到log10的影响,但会影响时,你的实际数据会在其他计算之前进行对数转换。 c $ c> scale_y_log10()这些值将被删除,并且所有计算都只包含部分数据,所以你得到的平均值与 coord_trans()一样大。 警告消息: 1:规模$ trans $ trans(x):NaNs产生 2:规模$ trans $ trans(x):NaNs产生 3:缺少值(stat_summary)。 4:删除了包含缺失值(stat_summary)的100行。 I am using log transforms for my statistical analyses (reaction times) and now I want to plot my data, with a log transformed y-axis. When I use coord_trans(ytrans = "log10") that gives me the right results - but I need bars instead of points for my graph.When I use scale_y_log10() it works with bars but it plots the wrong values (bar1 has a mean of 833 but is shown above 900; bar2 has a mean of 568 but is shown closer to 500).set.seed(10)bar1 <- abs(rnorm(n = 232, mean = 833, sd = 1103)) + 1bar2 <- abs(rnorm(n = 393, mean = 568, sd = 418)) + 1graph_data <- data.frame(RT = c(bar1, bar2), group = c(rep(1, 232), rep(2, 393)))ggplot(graph_data, aes(group, RT)) +stat_summary(fun.y = mean, geom = 'point', position = 'dodge') +stat_summary(fun.data = mean_cl_normal, geom = 'pointrange', position = 'position_dodge'(width = .9)) +coord_trans(ytrans = "log10")ggplot(graph_data, aes(group, RT)) +stat_summary(fun.y = mean, geom = 'bar', position = 'dodge') +stat_summary(fun.data = mean_cl_normal, geom = 'pointrange', position = 'position_dodge'(width = .9)) +scale_y_log10(breaks = seq(300, 1000, 100))Thanks for helping! 解决方案 There two reasons why you got different values.First, if you will look on the help page of the coord_trans() you will see that: coord_trans is different to scale transformations in that it occurs after statistical transformation and will affect the visual appearance of geoms - there is no guarantee that straight lines will continue to be straight.This mean that with coord_trans() only coordinates (y axis) are affected with log10 but with scale_y_log10() your actual data are log transformed before other calculations.Second, your data have negative values and when you apply scale_y_log10() to your data those values are removed and all calculations are made with only part of your data, so the mean value you get is larger as with coord_trans().Warning messages:1: In scale$trans$trans(x) : NaNs produced2: In scale$trans$trans(x) : NaNs produced3: Removed 100 rows containing missing values (stat_summary).4: Removed 100 rows containing missing values (stat_summary). 这篇关于scale_y_log10()和coord_trans(ytrans ='log10')导致不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 20:39