我正在使用facet_wrapggplot绘制时间序列值及其百分比:
对于下图,上图是值,下图是百分比变化。我希望下图中的 y 轴为“%”。通常在 ggplot 我会做类似的事情
+ scale_y_continuous(labels = scales::percent)
Run Code Online (Sandbox Code Playgroud)
但是由于我使用的是 facet_wrap,我如何指定我只希望 2 个图的 y 轴标签之一是百分比?
PS这是生成此图的代码:
library(data.table)
library(ggplot2)
library(scales)
library(dplyr)
pct <- function(x) {x/lag(x)-1}
Dates = seq(from = as.Date("2000-01-01"),
to =as.Date("2018-10-01"),
by = "1 month")
set.seed(1024)
this_raw = data.frame(CM = Dates,
value = rnorm(n = length(Dates)),
variable = rep("FAKE",length(Dates)))
this_diff = na.omit(as.data.table(this_raw %>%
group_by(variable) %>%
mutate_each(funs(pct), c(value))))
this_diff$type = "PerCng"
this_raw$type = "RAW"
plot_all = rbindlist(list(this_raw,this_diff))
plot_all$type = factor(plot_all$type, levels = c("RAW", "PerCng"))
out_gg = plot_all %>% …Run Code Online (Sandbox Code Playgroud) 我有一个列表和一个常量,我想知道列表中的哪些元素大于常量。
ls = [2, 1, 0, 1, 3, 2, 1, 2, 1]
constant = 1.5
Run Code Online (Sandbox Code Playgroud)
所以我只是做了:
ls >= constant
Run Code Online (Sandbox Code Playgroud)
我希望它返回:
[TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE]
Run Code Online (Sandbox Code Playgroud)
但是它返回了一个错误!!!
TypeError Traceback (most recent call last)
<ipython-input-92-91099ebca512> in <module>
----> 1 ls > constant
TypeError: '>' not supported between instances of 'list' and 'float'
Run Code Online (Sandbox Code Playgroud)
python 如何将向量与简单的常量值进行比较?