- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 geom_line() 的绘图顶部绘制一些线段。令人惊讶的是,geom_line() 的指南(图例)颜色被绘制为我添加到图中的最后一个元素的颜色 - 即使它不是 geom_line()。这对我来说似乎是一个错误,但由于某种我不明白的原因,这可能是预期的行为。
#Set up the data
require(ggplot2)
x <- rep(1:10, 2)
y <- c(1:10, 1:10+5)
fac <- gl(2, 10)
df <- data.frame(x=x, y=y, fac=fac)
#Draw the plot with geom_segment second, and the guide is the color of the segment
ggplot(df, aes(x=x, y=y, linetype=fac)) +
geom_line() +
geom_segment(aes(x=2, y=7, xend=7, yend=7), colour="red")
ggplot(df, aes(x=x, y=y, linetype=fac)) +
geom_segment(aes(x=2, y=7, xend=7, yend=7), colour="red") +
geom_line()
最佳答案
功能(ish)。绘制的引用线是线型的引用线。但是,它必须以某种颜色绘制才能看到。当美学映射未指定颜色时,ggplot2 以与绘图一致的颜色绘制它。我推测默认值是使用的最后一种颜色。这就是为什么当您以不同的顺序绘制它们时会看到差异的原因。
但是,您可以控制图例的这些细节。
ggplot(df, aes(x=x, y=y, linetype=fac)) +
geom_line() +
geom_segment(aes(x=2, y=7, xend=7, yend=7), colour="red") +
scale_linetype_discrete(guide=guide_legend(override.aes=aes(colour="blue")))
关于r - 当 geom_line() 和 geom_segment() 一起使用时,指南颜色似乎不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12478346/
我有下面的代码,它工作正常。问题是,我想添加“k”并绘制一条类似于“z”的直线,但“k”是不同数字的向量。 “k”中的每个元素都应绘制为创建的 3 个面上的一条线。如果 k 是一个奇异值,我会用不同的
在我更新到版本 2.2.0 之前,以下代码在 ggplot2 中有效。现在我得到了 Error: Aesthetics must be either length 1 or the same as t
我想使用 geom_segment 按因子组显示段簇,但 position 参数似乎没有任何作用。这是一个例子: mydata = data.frame(variable = factor(c("A"
我想弄清楚如何更改使用 geom_segment 的甘特图的边框颜色. 这是一些数据: df <- structure(list(start_int = c(0, 5, 0, 0, 9, 10, 12
我正在尝试在 ggplot 中构建网络图。两件事:1)我需要将节点放在特定的(x,y)值上。这不是问题。 2)网络图是定向的,但我需要能够显示从节点 B 到节点 A 与从节点 A 到节点 B 的差异。
使用 facet_grid 时,如何根据数据中的一个因素为 geom_segments 着色?我的方法失败了,因为颜色的分配是错误的。 这是一些数据: visual_data=data.frame(V
大家好,我需要帮助才能使用 ggplot2 获得一个不错的 geom_segment 图。 这是数据 structure(list(molecule = structure(c(1L, 1L, 2L,
ggplot(int_times,aes(x=-stim ,y=num,colour=gene)) + scale_y_continuous(breaks=int_times$num,l
我正在尝试使用 ggplot2 在直方图底部绘制一些线段,覆盖几条线段以指示分布的相关部分。我希望绿色段的厚度是灰色段的两倍,但绿色段似乎总是灰色段厚度的五倍。这是一些玩具数据和我的 ggplot2
下面的绘图代码使所有颜色的线段线会聚在离散 x 变量的中心。可以做些什么来使线段线对于每个 x 变量各自的颜色是垂直的? #~ Plot data ggplot(data = data0, aes(x
我正在制作一些室内和室外事件的相当复杂的情节,但我有点陷入困境。我想通过(Xmin、Ymin 和 Zmin)在 geom_segment 中添加对室内/室外花费的分钟数进行着色> 我的情节的步骤(见下
我正在尝试在 ggplot2 中制作一个带有箭头的绘图,看起来像这样,它是使用基本 R 图形制作的。 (颜色并不重要) 使用ggplot2: library(ggplot2) library(scal
下面的图有 2 个部分。 如何为线段添加图例? 理想情况下,最终结果有 2 个图例: 其中一个是当前的“点图例” 另一个图例是一个带有红色虚线标记为“段图例”的单个图例 这是代码 set.seed(1
我正在研究主成分分析 (PCA)。我发现ggfortify效果很好,但想做一些手动调整。 这里尝试绘制 PCA 结果如下: evec % ggplot(mapping = aes(x=PC1, y
我有两组纬度和经度变量,用于我的数据框中的大量行 (~100,000)。我正在尝试制作一个连接这两组坐标的图(即,从 latitude1,longitude1 到 latitude2,longitud
这是我的可重现示例: IND.factions <- rbind(c("Mughal Empire", "IND", "1526-1-1", "1857-1-1", "IND"),
这个问题在这里已经有了答案: geom_rect and alpha - does this work with hard coded values? (4 个回答) 去年关闭。 我在我的情节中尝试了
问题: 我想将 geom_hline 中的 geom_segment 添加到 3 个 stat_summary 点中的每一个,以确定每个物种的平均值。 当前代码: library(tidyverse)
我正在尝试通过 geom_segment 在绘图中放置一条引用线。 一个简化的例子: tryCatch({ spaghetti_smooth_ref = qplot(age,T_self, data=
我正在尝试获得类似于 Glen_b 对 this question 的回答的内容.基本上,我希望箱线图顶部有一个箭头,以指示使用 ggplot 时有更多超出比例的异常值。 我可以让情节的主要部分看起来
我是一名优秀的程序员,十分优秀!