- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如下面的示例数据集所示,日期介于 2015-01-01 和 2015-08-01 之间。但是,当我使用 date_breaks
函数时,x 轴中的月份标签会发生移动。您能提出一个解决方案吗?
dfn <- read.table(header=T, text='
supp p_date length
OJ 2015-01-01 13.23
OJ 2015-03-01 22.70
OJ 2015-08-01 26.06
VC 2015-01-01 7.98
VC 2015-03-01 16.77
VC 2015-08-01 26.14
')
dfn$p_date <- as.Date(dfn$p_date, "%Y-%m-%d")
library(ggplot2)
library(scales)
ggplot(dfn, aes(as.POSIXct(p_date), length, colour = factor(supp))) +
geom_line(size=1.3) +
labs(colour="Lines :", x = "", y = "") +
guides(colour = guide_legend(override.aes = list(size=5))) +
scale_x_datetime(breaks = date_breaks("1 months"),labels = date_format("%m/%y"))
这是我的 session 信息
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Greek_Greece.1253 LC_CTYPE=Greek_Greece.1253 LC_MONETARY=Greek_Greece.1253 LC_NUMERIC=C LC_TIME=Greek_Greece.1253
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_0.3.0 ggplot2_1.0.1
loaded via a namespace (and not attached):
[1] labeling_0.3 MASS_7.3-44 colorspace_1.2-6 magrittr_1.5 plyr_1.8.3 tools_3.2.2 gtable_0.1.2 reshape2_1.4.1
[9] Rcpp_0.12.1 stringi_0.5-5 grid_3.2.2 stringr_1.0.0 digest_0.6.8 proto_0.3-10 munsell_0.4.2
最佳答案
我注意到日期格式存在类似(但不相同)的问题,这似乎是由于 format
中时区的使用造成的。用于date_format()
.
你的基础情节
library(ggplot2)
library(scales)
p <- ggplot(dfn, aes(as.POSIXct(p_date), length, colour = factor(supp))) +
geom_point(size=3) +
geom_line(size=1.3) +
labs(colour="Lines :", x = "", y = "") +
guides(colour = guide_legend(override.aes = list(size=5))) +
theme(axis.text.x=element_text(size=15))
p + scale_x_datetime(breaks = date_breaks("1 month"),
labels = date_format("%m/%Y"))
哪个产生
请注意,三月已添加两次,这似乎是由于在格式函数中使用了时区信息
date_format()(date_breaks()(as.POSIXct(dfn$p_date[c(1,3)])))
#[1] "2015-01-01" "2015-02-01" "2015-03-01" "2015-03-31" "2015-04-30" "2015-05-31"
#[7] "2015-06-30" "2015-07-31" "2015-08-31"
您可以编写自己的格式函数,使其不包含任何时区信息。
my_format <- function (format = "%Y-%m-%d") {
function(x) format(x, format)
}
和情节
p + scale_x_datetime(breaks = date_breaks("1 month"),
labels = my_format("%m/%Y"))
这种格式的行为更像我所期望的
my_format()(date_breaks()(as.POSIXct(dfn$date2[c(1,3)])))
#[1] "2015-01-01" "2015-02-01" "2015-03-01" "2015-04-01" "2015-05-01" "2015-06-01"
#[7] "2015-07-01" "2015-08-01" "2015-09-01"
所以这并不是一个真正的解释,因为我对 POSIX 函数的理解很少,但确实建议了一种解决方法。
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8
[4] LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] datasets utils stats graphics grDevices grid methods base
other attached packages:
[1] scales_0.3.0 data.table_1.9.6 Hmisc_3.17-0 Formula_1.2-1 survival_2.38-3
[6] lattice_0.20-33 MASS_7.3-44 gridExtra_2.1.0 ggplot2_1.0.1.9003
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 digest_0.6.8 chron_2.3-47 plyr_1.8.3 gtable_0.1.2
[6] acepack_1.3-3.3 latticeExtra_0.6-26 rpart_4.1-10 labeling_0.3 proto_0.3-10
[11] splines_3.2.2 RColorBrewer_1.1-2 tools_3.2.2 foreign_0.8-66 munsell_0.4.2
[16] colorspace_1.2-6 cluster_2.0.3 nnet_7.3-11
关于r - date_breaks {scales} 改变 ggplot 中的日期刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348329/
我正在尝试在 View 中同时使用 scalegesture 监听器和 gesturelistener。如果比例为 1,则一切正常,但如果将比例设置为其他值,图像会跳到一个新位置,然后平滑缩放。 我的
我在使用 Canvas 和 canvas.scale(Scale, Scale) 时遇到图像质量问题;它们看起来完全像下面这样: android:运行时调整大小的图像质量 我相信我已经阅读了所有关于调
我有一个使用 svg 过滤器附加阴影的 svg 图形。我需要缩放阴影,但找不到可以执行此操作的过滤器。有谁知道这是否可能?
我正在构建一个逻辑回归分类器。 我从一组 500.000 条记录开始,我只想使用其中的一个样本。 你有什么建议: 1) 缩放总体然后采样2)缩放样本3) 仅缩放样本的 X_TRAIN 分割? 为什么?
我有一个功能,我用它在鼠标进入时放大图片并在鼠标离开时返回到正常大小。问题是,如果我在允许图片返回正常大小之前快速将鼠标移出然后将鼠标移入,那么图片将从鼠标输入时当前的任何大小放大(x2.7) (并且
可以在 scale-y-2 中使用 zoomtovalues 吗?我在多个 y 轴上有几个系列,我想将每个 scale-y-n 缩放到特定值,但我不知道如何... 谢谢和问候, 最佳答案 我们在最近的
我正在尝试在 Android 中创建(我认为是)一个相对简单的动画。也就是说,我想让某个 TextView 在单击按钮时缩小到 0 并返回到 1。当我单击该按钮时实际发生的是 TextView 立即缩
我有一个元素需要缩放到父元素的 100%。因为该元素包含基于像素的动画和可以缩放的图像,所以我不能使用百分比。有没有办法使用 css transform scale 来做到这一点? 最佳答案 相对 c
我在 ChartJS 中遇到一个奇怪的错误并且不知道如何修复它,由于这个错误我无法更改比例的任何内容。 我的代码(Sensor.tsx): import { useParams } from "sol
我有一些数据,我正试图通过不断增加的分母来准确和精确地处理这些数据。 请假设分子总是有小数。 我在 docs 中看到divide(BigDecimal divisor) 实际上会减小比例,这看起来很奇
喂, https://jsfiddle.net/jbwq6y87/7/ #box { width: 500px; height: 500px; transition: 0.5s; ov
几个 Tk 小部件也存在于 Ttk 版本中。通常它们具有相同的一般行为,但使用“样式”和“主题”而不是每个实例的外观属性(例如 bg 等)。这很好,因为 Ttk 小部件默认采用操作系统窗口管理器的“标
我尝试转换视频并使用 scale=-1:720 调整其大小,但出现错误“宽度不能被 2 整除”。我解决了这个问题:scale=-2:720。 之间有什么区别 scale=-1:720 和 scale=
我正在尝试重新创建此 codepen变换:我网站上特定页面的缩放转换,但它没有按预期工作 - 正如您在此代码片段中看到的那样(在整页上查看) - 图像覆盖/覆盖不足和不稳定而不是平滑。 /* Part
我有 3 个 Scale 小部件 scale1、scale2 和 scale3。我想使用 scale1 按以下方式控制 scale2 和 scale3 的值: 我不希望 scale2 和 scale3
我目前正在将我的数据分析从 R 转移到 Python。在 R 中缩放数据集时,我会使用 R.scale(),据我所知,它会执行以下操作:(x-mean(x))/sd(x) 为了替换该函数,我尝试使用
从文档中,定义为: 量化 ..a variant of linear scales with a discrete rather than continuous range. The input do
我有一个时基折线图,我正在尝试获取点击坐标处每个刻度的值。 我在 ChartJS 选项中指定的 onClick 函数: onClick: function(event, elementsAtEvent
我见过这样写的代码: ,但我也看到过这样写的代码: initial-scale=1 和 initial-scale=1.0 有区别吗? 最佳答案 没有。 specification描述视口(viewp
给定 y 轴 (s) 上的缩放和 x 轴 (t) 上的平移参数,当目的是最大化曲线叠加(而不是最小化距离)时,如何缩放和对齐两条不重合的曲线? 正如 @DWin 所指出的,这可能会被重新命名为“如何使
我是一名优秀的程序员,十分优秀!