- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 geom_bar
图,我想设置 geom_hline
的长度。
我有这些数据,
set.seed(666)
df <- data.frame(
date = seq(Sys.Date(), len= 156, by="4 day")[sample(156, 26)],
IndoorOutdoor = rep(c(-1,1), 13), #Change so there are only 26 rows
Xmin = sample(90, 26, replace = T),
Ymin = sample(90, 26, replace = T),
Zmin = sample(90, 26, replace = T)
)
df$XYZmin <- rowSums(df[,c("Xmin", "Ymin", "Zmin")])*df$IndoorOutdoor
df[,7:9] <- df[,3:5]*df[,2] #Adding the sign to each X/Y/Z
names(df)[7:9] <- paste0(names(df)[3:5],"p") #to differentiate from your X/Y/Z
require(ggplot2)
df.m <- melt(df[,c(1:2,6:9)], measure.vars=c("Xminp", "Yminp", "Zminp"))
df.m$pos <- c(as.Date("2013-04-15"), rep(Sys.Date(), (length(df.m$XYZmin)-1)))
df.m$foo <- 0
然后我尝试像这样绘制它
plot.alt <- ggplot(df.m, aes(date, value, fill=variable)) +
geom_bar(position="stack", stat="identity", width=0.5) +
geom_hline(aes(pos, foo), size = 0.8, colour = "green")
plot.alt
这给出了错误消息,
Warning message:
Stacking not well defined when ymin != 0
以及情节,
如果我尝试使用 pos
将其绘制为 as.numeric
,
df.m$pos <- as.numeric(df.m$pos)
我收到此错误,
Error: Invalid input: date_trans works with objects of class Date only
如何设置绿线的长度?
最佳答案
您可以将 geom_hline()
替换为 geom_segment()
并设置 x
值的起始位置和结束位置。
ggplot(df.m, aes(date, value, fill=variable)) +
geom_bar(position="stack", stat="identity", width=0.5) +
geom_segment(aes(x=min(pos),xend=max(pos),y=0,yend=0),colour="green")
关于r - 在 `geom_hline` 图中设置 `geom_bar` 的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392570/
我有一个使用 ggplot2 库的条形图: plot <- qplot(Date, data=cns, geom="bar", binwidth = 1,
我想在 ggplot 中使用 geom_hline 包含两条水平线。我的图表上的比例从 0 到 20,000,我希望在 400 和 17,000 处有一条线。 ?geom_hline给出单行( geo
我有一个用 ggplot (ggplot + geom_bar) 创建的直方图,我在其中添加了一行,如下所示: + geom_hline(aes(yintercept = 0.05), linetyp
我想在表示虚线的现有图例下添加一个图例,以便将虚线标记为“avg tx effect”并置于研究 3 之下。 library(ggplot2) library(ggthemes) #dput(df)
我的 ggplot 有以下代码 - facet_wrap 函数在页面上为每个 Name 绘制 20 个图,沿 x 轴有 5 个 Pcode。我想计算每个名称的平均 TE.Contr 并将该值绘制为每个
这个问题在这里已经有了答案: Display a summary line per facet rather than overall (1 个回答) 2年前关闭。 library(tidyverse
我环顾四周,但似乎找不到解决方案。我在 ggplot2 中使用了 geom_point 和 geom_hline 并且都得到了令人满意的图例。但是,我在图中有一条黑线和一条蓝线,但在图例中它们都是黑色
使用下面的数据,请注意图例没有正确描述 geom_hline: df<-data.frame( points=c(.153,.144,.126,.035, .037, .039, .010,.
geom_hline 似乎忽略了美观,我错过了什么还是这是一个错误? df session 信息: R version 3.4.4 (2018-03-15) Platform: x86_64-pc-
在下面的代码中,我创建了一个 ggplot,p1,使用来自 df1 的数据。我想在 df2 中的每个项目的 score 值处添加一条水平线,并使用包含在列 中的每个项目的相应十六进制代码为每行着色it
我正在尝试制作带有“时间标记”的图形。这些时间标记是某些日期的垂直线。时间数据为POSIXct格式。我想使用Plotly的出色交互界面,并在其中使用ggplot对象。 问题在于,使用ggplotly(
我有一个箱线图,想为每个箱线图单独添加带有 geom_hline 的简单水平线。 我尝试过 R 中的箱线图示例。问题是: 这些线条跨越整个图,而不仅仅是箱线图。 它们位于箱线图后面..;-) 感谢您提
问题: 我想将 geom_hline 中的 geom_segment 添加到 3 个 stat_summary 点中的每一个,以确定每个物种的平均值。 当前代码: library(tidyverse)
我想在我的图中添加一个图例,其中包含所有 hline 的统计描述。有什么办法可以做到吗? Link to plot def test_plot(): Q1=test['age'].quantile(0
我用 geom_hline() 和 geom_vline() 创建了一个散点图,该图很好,但图例条目不是我想要的显示方式。 vline (Restauration) 和 hline (Threshol
我想在 geom_hline 中为我的水平线创建一个图例。我使用的数据来自 3 个不同的数据帧。我也在使用 gghighlight,我相信它掩盖了任何传说。在这种情况下我如何强制传奇? 3个数据帧是:
输出(x) structure(list(Host = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "A", class
我正在尝试在带有小平面的 ggplot 中为 geom_vline 和 geom_hline 制作单独的图例。 这是我的代码: set.seed(1) vec1 = rnorm(20) set.see
我有一些代码绘制了一些值的直方图,以及一些水平线来表示要比较的引用点。但是,ggplot 不会生成线条的图例。 library(ggplot2) library(dplyr) ## Siumlate
我正在尝试在带有小平面的 ggplot 中为 geom_vline 和 geom_hline 制作单独的图例。 这是我的代码: set.seed(1) vec1 = rnorm(20) set.see
我是一名优秀的程序员,十分优秀!