- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用Plotly软件包作为Shiny应用程序的一部分在R中创建堆积面积图,并希望比较悬停时的数据。但是,出于设计原因,我隐藏了模式栏,因此我需要在代码中声明此选项,因为当前仅针对与光标最近的数据点显示悬停。
但是,Plotly for R reference仅提供选项“x”(x轴上的工具提示),“y”(y轴上的工具提示),“最近”(显示与光标最近的数据点的工具提示)和FALSE(禁用工具提示)。
有什么方法可以做我想做的事吗?请注意,这个问题与this one完全相反。
我使用的代码是:
plot_ly(data2,
x = ~Year,
y = ~B,
name = 'In-centre',
type = 'scatter',
mode = 'none',
fill = 'tozeroy',
fillcolor = '#F5FF8D',
hoverinfo = 'y') %>%
add_trace(y = ~A,
name = 'At home',
fillcolor = '#50CB86',
hoverinfo = 'y') %>%
layout(xaxis = list(title = "",
showgrid = FALSE,
tickangle = 270,
dtick = 1,
tickfont = list(size = 11)),
yaxis = list(title = "",
ticklen = 8,
tickcolor = "#EEEEEE",
range = c(-2, 101),
tick0 = 0,
dtick = 10,
tickfont = list(size = 11)),
showlegend = TRUE,
legend = list(x = 0,
y = -0.2,
orientation = "h",
traceorder = "normal"),
margin = list(t = 25, b = 50, r = 10, l = 40)) %>%
config(displayModeBar = FALSE)
Year A B
2006 18.0 82.0
2007 19.2 78.3
2008 17.9 80.2
2009 20.1 77.7
最佳答案
将layout(hovermode = 'compare')
添加到您的代码中:
data2 <- read.table(text="
Year A B
2006 18.0 82.0
2007 19.2 78.3
2008 17.9 80.2
2009 20.1 77.7
", header=T)
library(plotly)
library(dplyr)
plot_ly(data2,
x = ~Year,
y = ~B,
name = 'In-centre',
type = 'scatter',
mode = 'none',
fill = 'tozeroy',
fillcolor = '#F5FF8D',
hoverinfo = 'y') %>%
add_trace(y = ~A,
name = 'At home',
fillcolor = '#50CB86',
hoverinfo = 'y') %>%
layout(xaxis = list(title = "",
showgrid = FALSE,
tickangle = 270,
dtick = 1,
tickfont = list(size = 11)),
yaxis = list(title = "",
ticklen = 8,
tickcolor = "#EEEEEE",
range = c(-2, 101),
tick0 = 0,
dtick = 10,
tickfont = list(size = 11)),
showlegend = TRUE,
legend = list(x = 0,
y = -0.2,
orientation = "h",
traceorder = "normal"),
margin = list(t = 25, b = 50, r = 10, l = 40)) %>%
config(displayModeBar = FALSE) %>%
layout(hovermode = 'compare')
hovermode = 'x'
是记录在案的方式,可以实现完全相同的结果” 。
layout(hovermode = 'x')
关于R:将Plotly悬停模式设置为 "compare data on hover",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46730394/
我经常有一个 Comparator 类型,而我需要一个 Comparable 类型,反之亦然。是否有可重用的 JDK API 可以相互转换?类似的东西: public static Comp
我怎么能写这个 Comparator sort = (i1, i2) -> Boolean.compare(i2.isOpen(), i1.isOpen()); 像这样(代码不起作用): Compa
请帮助她。我有一个错误 Collections.sort(var4, new Comparator() { public int compare(TreeMap var1, TreeMa
学习 Kotlin,我试图了解 Java 的 Comparator接口(interface)有效 - 主要是 compare() 函数,这样我就可以利用它。 我已经尝试阅读 compare() 的文档
我有以下程序 List numbers = Arrays.asList("10", "68", "97", "9", "21", "12"); Collections.sort(numbers, (
我想根据嵌套类的属性对如下所示的列表进行排序。 class Test { private NestedClass nestedClass; private AnotherNes
我很好奇“Beyond Compare”的算法是如何工作的? 我猜想他们使用了一种标准的(众所周知的?)算法来实现“字符与字符”的比较。你知道这个算法的名字吗?谢谢 最佳答案 Beyond Compa
这个问题已经有答案了: How does the sort() method of the Collection class call the Comparable's compareTo()? (1
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicates: difference between compare() and compareTo() Java: What i
我被要求为某个类实现Comparable或Compartor,我们称之为V。 假设我有一个 V 的 Collection 或 Set(还不确定,但我认为这并不重要)。 V 有一个方法,可以评估它的“权
我正在查看Java8中实现的Comparator.comparing方法的源代码 这是代码 public static Comparator comparing( Function
假设我有一个类 ClassA,它的属性是 ClassB: public ClassA { private String attr; private ClassB classB; } p
我有一个自定义比较器,其比较逻辑如下: List l = new ArrayList(); l.add("tendercoupon"); l.add("giftcard
我正在努力实现一个处理 Comparator 和 Comparable 接口(interface)的层次结构。我不清楚的几件事: 如果我将比较器添加到比较器链中,这段代码究竟意味着什么 chain.a
正在关注 this question关于按另一个列表对列表进行排序,我尝试做同样的事情 - 但由于某种原因它对我不起作用。我错过了什么? List nums = Arrays.asList(5
假设我有一个像这样的领域模型: class Lecture { Course course; ... // getters } class Course { Teache
在表达式 > 中像这样的签名 public static > foo(T x) { ... } T的描述递归地依赖于Comparable . 如果T延伸Comparable ,和Comparable延
所有“数字”比较器(例如 Comparer.Default 、 Comparer.Default 等)返回 -1 的原因是什么? , 0或 1 ,但是 Comparer.Default和 Compar
(如果这是重复的,请指出正确的答案!我搜索并阅读了几个(> 5)个相关问题,但似乎没有一个是正确的。还查看了泛型常见问题解答和其他来源...) 当一个集合类接受一个比较器时,它应该具有 Compara
SBCL 1.3.1 综上所述,a是一个列表,'(7),b通过setq sbcl This is SBCL 1.3.1.debian, an implementation of ANSI Common
我是一名优秀的程序员,十分优秀!