Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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:如何使用列名作为x轴标签,使用值作为y轴标签_R_Ggplot2 - Fatal编程技术网

R ggplot:如何使用列名作为x轴标签,使用值作为y轴标签

R ggplot:如何使用列名作为x轴标签,使用值作为y轴标签,r,ggplot2,R,Ggplot2,找不到解决这个问题的方法 我想绘制一个包含4列的数据框,如下所示: 种 今天的意义 平均RCP26 平均RCP85 1. 0.567 0.765 0.342 2. 0.987 0.543 0.001 3. 0.456 0.876 0.54 您需要首先旋转数据,这是通过聚集实现的,您还需要组美学来获得具有离散x轴的线 require(dplyr) require(ggplot2) df %>% gather(var, val , -Species) %>% ggplot(

找不到解决这个问题的方法

我想绘制一个包含4列的数据框,如下所示:

种 今天的意义 平均RCP26 平均RCP85 1. 0.567 0.765 0.342 2. 0.987 0.543 0.001 3. 0.456 0.876 0.54
您需要首先旋转数据,这是通过
聚集
实现的,您还需要
美学来获得具有离散x轴的线

require(dplyr)
require(ggplot2)
    
df %>% 
gather(var, val , -Species) %>% 
ggplot(aes(x = var, y = val, color = as.factor(Species), group = as.factor(Species)))+
geom_line() 

我还使用了
tidyr
来透视表

library(ggplot2)
library(dplyr)
library(tidyr)

df %>% 
  pivot_longer(cols = 2:4, names_to = "indicators", values_to = "values") %>% 
  ggplot(data = ., aes(x = indicators, y = values, color = as.factor(Species), group = Species)) +
    geom_point()
输出:


请以便于受访者使用的方式显示您的数据。gather()的开发已经完成,对于新代码,我们建议切换到pivot_longer()。