Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何使用ggplot显示排名_R_Ggplot2_Geom Bar - Fatal编程技术网

R 如何使用ggplot显示排名

R 如何使用ggplot显示排名,r,ggplot2,geom-bar,R,Ggplot2,Geom Bar,我有以下数据框 Country<-c("Chile_T", "Canada_T", "El Salvador_N", "Finland_N", "Germany_N", "Germany_T") Loss<-c(1.14e-06, 6.14e-07, 8.93e-09, 8.93e-09, 1.05e-10, 1.25e-11) df<- data.frame(Country, Loss) 请问,有人能给我指一下正确的方向吗?提前感谢 您可以使用重新排序: Countr

我有以下数据框

Country<-c("Chile_T", "Canada_T", "El Salvador_N", "Finland_N", "Germany_N", "Germany_T")
Loss<-c(1.14e-06, 6.14e-07, 8.93e-09, 8.93e-09, 1.05e-10, 1.25e-11)
df<- data.frame(Country, Loss)   

请问,有人能给我指一下正确的方向吗?提前感谢

您可以使用
重新排序

Country<-c("Chile_T", "Canada_T", "El Salvador_N", "Finland_N", "Germany_N", "Germany_T")
Loss<-c(1.14e-06, 6.14e-07, 8.93e-09, 8.93e-09, 1.05e-10, 1.25e-11)
df<- data.frame(Country, Loss)   
library(ggplot2)
ggplot(data=df, aes(x=reorder(Country, Loss), y=Loss))+
  geom_bar(stat = "identity", width=0.95, fill="black") + 
  coord_flip()

Country您可以使用
reorder

Country<-c("Chile_T", "Canada_T", "El Salvador_N", "Finland_N", "Germany_N", "Germany_T")
Loss<-c(1.14e-06, 6.14e-07, 8.93e-09, 8.93e-09, 1.05e-10, 1.25e-11)
df<- data.frame(Country, Loss)   
library(ggplot2)
ggplot(data=df, aes(x=reorder(Country, Loss), y=Loss))+
  geom_bar(stat = "identity", width=0.95, fill="black") + 
  coord_flip()

country也许你也可以帮我解决由此产生的问题。。。我对德国的价值观是如此之小,以至于酒吧根本不存在。。。有没有一种方法可以巧妙地变换轴,使所有的条都可见?我尝试了scale_y_log10(),但它奇怪地“翻转”了图表……它翻转了图表,因为你的值的对数是负数。你试过缩放吗?
?或者事先让你的小损失数字变大。谢谢!我现在使用的是平方根刻度。我真的不喜欢用这些东西,因为它们会让阅读变得不那么有趣。但效果很好。所以谢谢你的帮助:-)也许你也可以帮我解决由此产生的问题。。。我对德国的价值观是如此之小,以至于酒吧根本不存在。。。有没有一种方法可以巧妙地变换轴,使所有的条都可见?我尝试了scale_y_log10(),但它奇怪地“翻转”了图表……它翻转了图表,因为你的值的对数是负数。你试过缩放吗?
?或者事先让你的小损失数字变大。谢谢!我现在使用的是平方根刻度。我真的不喜欢用这些东西,因为它们会让阅读变得不那么有趣。但效果很好。所以谢谢你的帮助:-)