Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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
在GGR PLOT中绘制数据帧显示美学错误_R_Ggplot2 - Fatal编程技术网

在GGR PLOT中绘制数据帧显示美学错误

在GGR PLOT中绘制数据帧显示美学错误,r,ggplot2,R,Ggplot2,我有以下数据帧: 数据帧(habSolyc05g052120.2): 我只是试着做一个简单的点图,在加入其他物种的基因表达水平来找出这个基因之前。我尝试了以下不同的代码: ggplot(habSolyc05g052120.2, aes(x = habSolyc05g052120.2[,1:6], y = habSolyc05g052120.2[1,])) + geom_point() 它们都不起作用,每一个都会输出某个版本的错误: Error: Aesthetics must be eit

我有以下数据帧:

数据帧(habSolyc05g052120.2):

我只是试着做一个简单的点图,在加入其他物种的基因表达水平来找出这个基因之前。我尝试了以下不同的代码:

ggplot(habSolyc05g052120.2, aes(x = habSolyc05g052120.2[,1:6],
y = habSolyc05g052120.2[1,])) +
 geom_point()

它们都不起作用,每一个都会输出某个版本的错误:

Error: Aesthetics must be either length 1 or the same as the data (1): x and y

不知道如何为data.frame类型的对象自动拾取比例。默认为连续。

ggplot
中,为了美观,您不应该索引数据帧,它自己获取所有变量
我不知道您的数据帧结构,因为您的问题格式不好,但可能是您想要的:

library(ggplot2)
library(tidyverse)

# creating a dataframe similar to yours
habSolyc05g052129.2 <- data.frame(
  Shab_ovul1 = 0,
  Shab_poll1 = 0.6145496,
  Shab_poll2 = 0.368,
  Shab_styl1 = 0.043,
  Shab_styl2 = 0.0026,
  Shab_styl3 = 0.0405
)

# reshaping daraframe to ling format
habSolyc05g052129.2 <- habSolyc05g052129.2 %>% 
  pivot_longer(cols = 1:6, names_to = "Variables", values_to = "Values")

# main plot
ggplot(habSolyc05g052129.2, aes(x = Variables, y = Values)) +
  geom_point()

库(ggplot2)
图书馆(tidyverse)
#创建一个类似于您的数据帧

habSolyc05g052129.2是否尝试将
数据框中的6列用于
x
?然后对于
y
,您只选择其整体中的第一行?请记住,在
data.frame中,每个变量一列,每个观察值一行。然后,您可以有一个用于
x
的变量和一个用于
y
的变量。制作一个长格式的数据帧。有几个选项,但是tidyr::pivot_longer()工作得很好。非常感谢,它做得很好。将来我应该如何更好地展示我的数据?@tbiewerh,SO的常用格式是
dput
format。您可以阅读它的文档和教程。
ggplot(habSolyc05g052120.2) +
geom_point(aes(x = (colnames(habSolyc05g052120.2)),
y = habSolyc05g052120.2[1,]))
ggplot(habSolyc05g052120.2[1,]) +
geom_point(aes(x = (colnames(habSolyc05g052120.2)),
y = habSolyc05g052120.2[1,], fill = colnames(habSolyc05g052120.2)))
Error: Aesthetics must be either length 1 or the same as the data (1): x and y
library(ggplot2)
library(tidyverse)

# creating a dataframe similar to yours
habSolyc05g052129.2 <- data.frame(
  Shab_ovul1 = 0,
  Shab_poll1 = 0.6145496,
  Shab_poll2 = 0.368,
  Shab_styl1 = 0.043,
  Shab_styl2 = 0.0026,
  Shab_styl3 = 0.0405
)

# reshaping daraframe to ling format
habSolyc05g052129.2 <- habSolyc05g052129.2 %>% 
  pivot_longer(cols = 1:6, names_to = "Variables", values_to = "Values")

# main plot
ggplot(habSolyc05g052129.2, aes(x = Variables, y = Values)) +
  geom_point()