我正在绘制两个不同年份(07和08)的数据。这两年的日期略有不同,但是当我在R中绘制它时,我无法获得所有日期,R将它们重新排列为降序,或者在两个不同的年份中将它们分开,并在它们之间留出空格。
我需要彼此重叠,有些日期略有偏差。
日期应为:
data_07 [,1] -C(" 7/6""6分之21""6分之31"" 14/7"" 28/7"" 11/8""8分之25"" 8/9" )
data_08 [,1] -C(" 7/6""6分之21"" 5/7""七分之一十九""8分之2""八分之一十六""8分之25"" 8/9" )
$args = array(
'tinymce' => true,
'teeny' => true,
);
wp_editor( $Value, $Name, $args );
add_filter( 'teeny_mce_buttons', 'my_editor_buttons', 10, 2 );
function my_editor_buttons( $buttons, $editor_id ) {
return array( 'formatselect', 'bold', 'italic' );
}
感谢任何帮助和建议。 谢谢!
丹尼尔
答案 0 :(得分:1)
如果年份对于情节不重要,我建议在指示年份的数据中指定一个新列,将所有日期转换为普通年份,然后将它们分组绘制。
library(dplyr)
library(ggplot2)
library(lubridate)
#* dates are initially stored in dd/mm format.
#* create a variable where year = 2007
#* turn all dates to dd/mm/2000
data_07 <- data.frame(date = c("7/6","21/6","31/6","14/7","28/7","11/8","25/8","8/9"),
y = rnorm(8),
stringsAsFactors=FALSE) %>%
mutate(year = 2007,
date = dmy(paste0(date,"/2000")))
data_08 <- data.frame(date = c("7/6","21/6","5/7","19/7","2/8","16/8","25/8","8/9"),
y = rnorm(8),
stringsAsFactors=FALSE) %>%
mutate(year = 2008,
date = dmy(paste0(date,"/2000")))
both_years <- bind_rows(data_07, data_08)
ggplot(data = both_years,
mapping = aes(x = date,
y = y,
colour = factor(year))) +
geom_point() +
geom_line()
答案 1 :(得分:0)
这两行解决了我的问题:
data$Date<-as.Date(data$Date, format="%d/%m/%Y")
scale_x_date(labels = date_format("%d/%m"))