r - 尝试添加点是折线图的特定点删除了线条
问题描述
下面我显示了我的数据框的一部分,dput()
以确保没有问题。然后我尝试用ggplotly()
. 我想要实现的是在列中有数据的折线图中添加点或点或气泡,Marketing/Product
并且label_text
. Marketing/Product
此外,这些点的工具提示还应包括label_text
其他列。问题是现在根本不显示线条,只有点可见。代码位于数据集下方。
to<-structure(list(int_end = structure(c(18660, 18682, 18682, 18689,
18694, 18710, 18715, 18715, 18715, 18716, 18716, 18716, 18717,
18717, 18717, 18718, 18718, 18718, 18719, 18719, 18719, 18720,
18720, 18720, 18721, 18721, 18721, 18722, 18722, 18722, 18723,
18723, 18723, 18724, 18724, 18724, 18725, 18725, 18725, 18726,
18726, 18726, 18727, 18727, 18727, 18728, 18728, 18728, 18729,
18729), class = "Date"), interval = structure(c(NA, NA, NA, NA,
NA, NA, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L), .Label = c("30", "29", "28",
"27", "26", "25", "24", "23", "22", "21", "20", "19", "18", "17",
"16", "15", "14", "13", "12", "11", "10", "9", "8", "7", "6",
"5", "4", "3", "2", "1"), class = "factor"), user_type = structure(c(NA,
NA, NA, NA, NA, NA, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L,
1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L,
3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L,
2L), .Label = c("total", "inactive", "active"), class = "factor"),
users = c(NA, NA, NA, NA, NA, NA, 406L, 4311L, 4717L, 414L,
4320L, 4734L, 418L, 4333L, 4751L, 412L, 4356L, 4768L, 383L,
4389L, 4772L, 385L, 4388L, 4773L, 361L, 4414L, 4775L, 344L,
4435L, 4779L, 414L, 4385L, 4799L, 441L, 4383L, 4824L, 447L,
4403L, 4850L, 475L, 4395L, 4870L, 475L, 4399L, 4874L, 479L,
4398L, 4877L, 545L, 4358L), `Marketing / Product` = c("P",
"P", "P", "P", "P", "M", NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA), Title = c("New product: GBB Directory",
"New profile feature: Sprachen, Zahlungsmöglichkeiten, Barrierefreiheit",
"New profile feature: Ausbildungen", "Notification: new duplicates",
"Improvement: Activity Filter", "Activity Item: Penta cooperation",
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
`Short Description` = c("The order import was extended by the products GBB directory. As soon as a client is booking this directory product the client is getting a SDE account.",
"SDE users have the possibility to publish \"Sprachen, Zahlungsmöglichkeiten, Barrierefreiheit\" in their profile.",
"SDE users have the possibility to publish up to 3 \"Ausbildungsangebote\" and a badge f.ex. from the IHK in their profile.",
"Listing clients are informed about new duplicates in their Listing profile via Email and Activity Stream. The user has to check the duplicates in the area of \"Online-Einträge\".",
"The activity filter was improved and simplified based on user feedback.",
"All SDE users were getting the activity items for the cooperation with Penta. With this item the user has the possibility to get Penta to special conditions (financing software).",
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
description = c("The order import was extended\nby the products GBB directory.\nAs soon as a client is booking\nthis directory product the\nclient is getting a SDE\naccount.",
"SDE users have the possibility\nto publish \"Sprachen,\nZahlungsmöglichkeiten,\nBarrierefreiheit\" in their\nprofile.",
"SDE users have the\npossibility to publish up to\n3 \"Ausbildungsangebote\" and\na badge f.ex. from the IHK in\ntheir profile.",
"Listing clients are informed\nabout new duplicates in their\nListing profile via Email and\nActivity Stream. The user has\nto check the duplicates in the\narea of \"Online-Einträge\".",
"The activity filter was\nimproved and simplified based\non user feedback.",
"All SDE users were getting\nthe activity items for the\ncooperation with Penta. With\nthis item the user has the\npossibility to get Penta to\nspecial conditions (financing\nsoftware).",
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
label_text = structure(c("Details: The order import was extended\nby the products GBB directory.\nAs soon as a client is booking\nthis directory product the\nclient is getting a SDE\naccount.",
"Details: SDE users have the possibility\nto publish \"Sprachen,\nZahlungsmöglichkeiten,\nBarrierefreiheit\" in their\nprofile.",
"Details: SDE users have the\npossibility to publish up to\n3 \"Ausbildungsangebote\" and\na badge f.ex. from the IHK in\ntheir profile.",
"Details: Listing clients are informed\nabout new duplicates in their\nListing profile via Email and\nActivity Stream. The user has\nto check the duplicates in the\narea of \"Online-Einträge\".",
"Details: The activity filter was\nimproved and simplified based\non user feedback.",
"Details: All SDE users were getting\nthe activity items for the\ncooperation with Penta. With\nthis item the user has the\npossibility to get Penta to\nspecial conditions (financing\nsoftware).",
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), class = c("glue",
"character")), text = c("int_end: 2021-02-02<br>users: NA<br>user_type: NA<br>Marketing / Product: P<br>label_text: Details: The order import was extended\nby the products GBB directory.\nAs soon as a client is booking\nthis directory product the\nclient is getting a SDE\naccount.",
"int_end: 2021-02-24<br>users: NA<br>user_type: NA<br>Marketing / Product: P<br>label_text: Details: SDE users have the possibility\nto publish \"Sprachen,\nZahlungsmöglichkeiten,\nBarrierefreiheit\" in their\nprofile.",
"int_end: 2021-02-24<br>users: NA<br>user_type: NA<br>Marketing / Product: P<br>label_text: Details: SDE users have the\npossibility to publish up to\n3 \"Ausbildungsangebote\" and\na badge f.ex. from the IHK in\ntheir profile.",
"int_end: 2021-03-03<br>users: NA<br>user_type: NA<br>Marketing / Product: P<br>label_text: Details: Listing clients are informed\nabout new duplicates in their\nListing profile via Email and\nActivity Stream. The user has\nto check the duplicates in the\narea of \"Online-Einträge\".",
"int_end: 2021-03-08<br>users: NA<br>user_type: NA<br>Marketing / Product: P<br>label_text: Details: The activity filter was\nimproved and simplified based\non user feedback.",
"int_end: 2021-03-24<br>users: NA<br>user_type: NA<br>Marketing / Product: M<br>label_text: Details: All SDE users were getting\nthe activity items for the\ncooperation with Penta. With\nthis item the user has the\npossibility to get Penta to\nspecial conditions (financing\nsoftware).",
"int_end: 2021-03-29<br>users: 406<br>user_type: active",
"int_end: 2021-03-29<br>users: 4311<br>user_type: inactive",
"int_end: 2021-03-29<br>users: 4717<br>user_type: total",
"int_end: 2021-03-30<br>users: 414<br>user_type: active",
"int_end: 2021-03-30<br>users: 4320<br>user_type: inactive",
"int_end: 2021-03-30<br>users: 4734<br>user_type: total",
"int_end: 2021-03-31<br>users: 418<br>user_type: active",
"int_end: 2021-03-31<br>users: 4333<br>user_type: inactive",
"int_end: 2021-03-31<br>users: 4751<br>user_type: total",
"int_end: 2021-04-01<br>users: 412<br>user_type: active",
"int_end: 2021-04-01<br>users: 4356<br>user_type: inactive",
"int_end: 2021-04-01<br>users: 4768<br>user_type: total",
"int_end: 2021-04-02<br>users: 383<br>user_type: active",
"int_end: 2021-04-02<br>users: 4389<br>user_type: inactive",
"int_end: 2021-04-02<br>users: 4772<br>user_type: total",
"int_end: 2021-04-03<br>users: 385<br>user_type: active",
"int_end: 2021-04-03<br>users: 4388<br>user_type: inactive",
"int_end: 2021-04-03<br>users: 4773<br>user_type: total",
"int_end: 2021-04-04<br>users: 361<br>user_type: active",
"int_end: 2021-04-04<br>users: 4414<br>user_type: inactive",
"int_end: 2021-04-04<br>users: 4775<br>user_type: total",
"int_end: 2021-04-05<br>users: 344<br>user_type: active",
"int_end: 2021-04-05<br>users: 4435<br>user_type: inactive",
"int_end: 2021-04-05<br>users: 4779<br>user_type: total",
"int_end: 2021-04-06<br>users: 414<br>user_type: active",
"int_end: 2021-04-06<br>users: 4385<br>user_type: inactive",
"int_end: 2021-04-06<br>users: 4799<br>user_type: total",
"int_end: 2021-04-07<br>users: 441<br>user_type: active",
"int_end: 2021-04-07<br>users: 4383<br>user_type: inactive",
"int_end: 2021-04-07<br>users: 4824<br>user_type: total",
"int_end: 2021-04-08<br>users: 447<br>user_type: active",
"int_end: 2021-04-08<br>users: 4403<br>user_type: inactive",
"int_end: 2021-04-08<br>users: 4850<br>user_type: total",
"int_end: 2021-04-09<br>users: 475<br>user_type: active",
"int_end: 2021-04-09<br>users: 4395<br>user_type: inactive",
"int_end: 2021-04-09<br>users: 4870<br>user_type: total",
"int_end: 2021-04-10<br>users: 475<br>user_type: active",
"int_end: 2021-04-10<br>users: 4399<br>user_type: inactive",
"int_end: 2021-04-10<br>users: 4874<br>user_type: total",
"int_end: 2021-04-11<br>users: 479<br>user_type: active",
"int_end: 2021-04-11<br>users: 4398<br>user_type: inactive",
"int_end: 2021-04-11<br>users: 4877<br>user_type: total",
"int_end: 2021-04-12<br>users: 545<br>user_type: active",
"int_end: 2021-04-12<br>users: 4358<br>user_type: inactive"
)), row.names = c(NA, -50L), class = c("data.table", "data.frame"
), sorted = "int_end")
plot <- to %>%
ggplot(aes(int_end, users, color = user_type,text = text)) +
geom_point(data = filter(to, !is.na(`Marketing / Product`) | !is.na(label_text)))+
geom_line()+
theme_bw() +
scale_y_continuous(labels = scales::label_number_si(accuracy = 0))+
#theme(legend.position = "none")+
theme(legend.position = 'top')+
labs(title = glue::glue("Number of Users over time."),
subtitle = glue::glue("Interval window of days."),
y = "", x = "")
ggplotly(plot,tooltip="text")%>%
layout(legend = list(
orientation = "h",y=1.06
)
)
解决方案
除了添加group
我评论中提到的美学之外,您NA
对图例中 s 的问题可以通过过滤数据来解决,这也解决了空白空间的问题。
library(plotly)
to <- filter(to, !is.na(user_type))
plot <- to %>%
ggplot(aes(int_end, users, text = text, color = user_type, group = user_type)) +
geom_point(data = filter(to, !is.na(`Marketing / Product`) | !is.na(label_text))) +
geom_line() +
theme_bw() +
scale_y_continuous(labels = scales::label_number_si(accuracy = 0)) +
theme(legend.position = "top") +
labs(
title = glue::glue("Number of Users over time."),
subtitle = glue::glue("Interval window of days."),
y = "", x = ""
)
ggplotly(plot, tooltip = "text") %>%
layout(legend = list(
orientation = "h", y = 1.06
))
推荐阅读
- python - Python数据类型不能在while循环中改变
- mysql - 使用连接或子查询更新表 MYSQL 中的每一行
- android - 当我说要导入时(无法解析符号 V7)
- c - 使用变量参数不能打印正确的整数
- javascript - 文档参考.get(
) 不工作 - haskell - 在 haskell 中,为什么 min 8.0 8 = 8.0 和 max 8.0 8 = 8.0
- python - Flask:如何在 Flask、celery 或 python 多处理模块中创建一个或多个耗时的进程
- javascript - 为什么这个箭头函数绑定“this”的方式与类函数指针不同?
- node.js - cors 出现在 React 而不是 Node.js 为什么?
- html - 带有 HTML 控件的 javascript 3d