尝试添加点是折线图的特定点删除了线条
Posted
技术标签:
【中文标题】尝试添加点是折线图的特定点删除了线条【英文标题】:Trying to add dots is specific points of line chart removed the lines 【发布时间】:2021-09-10 23:26:54 【问题描述】:下面我使用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
)
)
【问题讨论】:
您好 Firmo23。对不起。尝试将group=user_type
添加到 aes() 中,就像我在回答您之前的问题时所做的那样。我忘了在那里提。添加text
aes 时我遇到了同样的问题。但是添加组 aes 修复了它。
感谢其他两个可能需要修复的事情是图例中的 NA,这是无用的,尤其是图表应该从有数据的点开始显示,并且在 4 月之前没有那么多空白空间
【参考方案1】:
除了添加我在评论中提到的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
))
【讨论】:
以上是关于尝试添加点是折线图的特定点删除了线条的主要内容,如果未能解决你的问题,请参考以下文章
如何用MATLAB做双纵坐标图?其中一条是折线图,另一个是柱形图,还有我想做多子图的
在折线图的特定位置添加点或点,并使用 ggplotly() 相应地调整工具提示
R语言使用plot函数和lines函数可视化多条折线图(线图line charts)进行对比分析设置type参数自定义线条和点的关系设置lty设置线条类型col设置颜色pch设置点形状等