如何从X和Y参数中的多个列中输入GGPLOT中的数据

发布于 2025-02-04 13:34:17 字数 321 浏览 1 评论 0原文

我正在尝试为粒度数据创建密度图。我的数据为每个基因型集具有多个密度和大小读数。有没有办法使用GGPLOT将多列指定为X和Y?我尝试为此进行编码,但到目前为止,我只得到了空白的情节。这是我使用的CSV文件的链接:

crop.data6 <- read.csv("barleygt25.csv", header = TRUE)
crop.data6

library(ggplot2)

plot1 = ggplot(data=crop.data6, aes(x=, xend=bq, y=a, yend=bq, color=genotype))
plot1

I am trying to create a density plot for particle size data. My data has multiple density and size readings for each genotype set. Is there a way to specify multiple columns into x and y using ggplot? I tried coding for this but am only getting a blank plot as of now. This is the link to the csv file I used: https://drive.google.com/file/d/11djXTmZliPCGLCZavukjb0TT28HsKMRQ/view?usp=sharing

Thanks!

crop.data6 <- read.csv("barleygt25.csv", header = TRUE)
crop.data6

library(ggplot2)

plot1 = ggplot(data=crop.data6, aes(x=, xend=bq, y=a, yend=bq, color=genotype))
plot1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昨迟人 2025-02-11 13:34:17

您的数据是一种奇怪的格式,无法很好地绘制绘图。有效地,它需要对其进行转换,然后旋转为长格式,以使其适合绘制:

df <- data.frame(xvals    = c(t(crop.data6[1:9, -c(1:2)])),
                 yvals    = c(t(crop.data6[10:18, -c(1:2)])),
                 genotype = rep(crop.data6$genotype[1:9], each = 68))

ggplot(df, aes(xvals, yvals, color = genotype)) +
  geom_line(size = 1) +
  scale_color_brewer(palette = "Set1") +
  theme_bw(base_size = 16) +
  labs(x = "value", y = "density")

”在此处输入图像说明”

Your data is in a strange format that doesn't lend itself well to plotting. Effectively, it needs to be transposed then pivoted into long format to make it suitable for plotting:

df <- data.frame(xvals    = c(t(crop.data6[1:9, -c(1:2)])),
                 yvals    = c(t(crop.data6[10:18, -c(1:2)])),
                 genotype = rep(crop.data6$genotype[1:9], each = 68))

ggplot(df, aes(xvals, yvals, color = genotype)) +
  geom_line(size = 1) +
  scale_color_brewer(palette = "Set1") +
  theme_bw(base_size = 16) +
  labs(x = "value", y = "density")

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文