以下のRコードを実行するとError: Invalid input: date_trans works with objects of class Date onlyというメッセージが出てしまいます。
scale_x_date(breaks = time_label, date_labels = "%m/%d")あたりのフォーマットがいけないのかなと推測しているのですが、どの様に修正すれば良いかがわかりません。
教えていただきたいです。
使用しているcsvデータをHTMLに変換したものも載せておきます。
よろしくお願いします。
library(tidyverse)
library(magrittr)
library(ggrepel)
library(conflicted)
conflict_prefer(name = "filter", winner = "dplyr")
setwd("~/desktop")
data <- read.csv("weight_2020.csv")
data %>%
filter(!is.na(turn_time)) %>%
pull(turn_time) -> time_label
data %>%
ggplot(aes(x=time, y=weight, group=1, label=label, color = 'factor(turn)', size = 'factor(turn)')) +
geom_line(size=0.3,color='grey50') +
geom_point() +
geom_blank(aes(y=0.5)) +
geom_text_repel(size=5,nudge_y = 0.8, segment.size = 0.2) +
scale_color_manual(values = c('grey40', 'red3')) +
scale_size_manual(values = c(1,3)) +
scale_x_date(breaks = time_label, date_labels = "%m/%d") +
theme_bw() +
theme(panel.border = element_blank(),
panel.background =element_blank(),
panel.grid.major = element_line(size = 0.3, color = "grey92"),
panel.grid.minor = element_blank(),
plot.margin = unit(rep(0.5, 4), "cm"),
title = element_text(size = 12),
axis.line = element_line(color = "grey50", size = 0.2),
axis.ticks = element_blank(),
axis.ticks.length = unit(0.04, "cm"),
axis.text = element_text(size = 10),
axis.title.x = element_blank(),
axis.title.y = element_text(size = 11),
text = element_text(family = "HiraKakuPro-w3"),
legend.position = "None") +
labs(y = "体重減少分(kg)") +
ggtitle('30日間ダイエット(8月20日からの減少分)')
<table>
<thead>
<tr>
<th>time weight turn_1kg turn_time label</th>
</tr>
</thead>
<tbody>
<tr>
<td>2020-08-20 0 1 2020-08-20 0kg</td>
</tr>
<tr>
<td>2020-08-21 -0.1 0 NA NA</td>
</tr>
<tr>
<td>2020-08-22 0.2 0 NA NA</td>
</tr>
<tr>
<td>2020-08-23 0.1 0 NA NA</td>
</tr>
<tr>
<td>2020-08-24 0.1 0 NA NA</td>
</tr>
<tr>
<td>2020-08-25 0.5 0 NA NA</td>
</tr>
<tr>
<td>2020-08-26 -0.5 0 NA NA</td>
</tr>
<tr>
<td>2020-08-27 -0.8 0 NA NA</td>
</tr>
<tr>
<td>2020-08-28 -1.3 1 2020-08-28 -1kg</td>
</tr>
<tr>
<td>2020-08-29 0.1 0 NA NA</td>
</tr>
<tr>
<td>2020-08-30 1 0 NA NA</td>
</tr>
<tr>
<td>2020-08-31 -0.3 0 NA NA</td>
</tr>
<tr>
<td>2020-09-01 -1.4 0 NA NA</td>
</tr>
<tr>
<td>2020-09-02 -1.1 0 NA NA</td>
</tr>
<tr>
<td>2020-09-03 -1.3 0 NA NA</td>
</tr>
<tr>
<td>2020-09-04 -1.2 0 NA NA</td>
</tr>
<tr>
<td>2020-09-05 -1.5 0 NA NA</td>
</tr>
<tr>
<td>2020-09-06 -1.8 0 NA NA</td>
</tr>
<tr>
<td>2020-09-07 -2.1 1 2020-09-07 -2kg</td>
</tr>
<tr>
<td>2020-09-08 -2.2 0 NA NA</td>
</tr>
<tr>
<td>2020-09-09 -2.1 0 NA NA</td>
</tr>
<tr>
<td>2020-09-10 -2.6 0 NA NA</td>
</tr>
<tr>
<td>2020-09-11 -2.5 0 NA NA</td>
</tr>
<tr>
<td>2020-09-12 -2.7 0 NA NA</td>
</tr>
<tr>
<td>2020-09-13 -2.1 0 NA NA</td>
</tr>
<tr>
<td>2020-09-14 -3.2 1 2020-09-14 -3kg</td>
</tr>
<tr>
<td>2020-09-15 -3.1 0 NA NA</td>
</tr>
<tr>
<td>2020-09-16 -3.6 0 NA NA</td>
</tr>
<tr>
<td>2020-09-17 -3.6 0 NA NA</td>
</tr>
<tr>
<td>2020-09-18 -4.1 1 2020-09-18 -4kg</td>
</tr>
<tr>
<td>2020-09-19 -4.1 0 NA NA</td>
</tr>
<tr>
<td>2020-09-20 -4.2 0 NA NA</td>
</tr>
<tr>
<td>2020-09-21 -3.9 0 NA NA</td>
</tr>
<tr>
<td>2020-09-22 -4.4 0 NA NA</td>
</tr>
<tr>
<td>2020-09-23 -5 1 2020-09-23 -5kg</td>
</tr>
<tr>
<td>2020-09-24 -5.2 0 NA NA</td>
</tr>
</tbody>
</table>