Creating Data specific graphs with GGplot and need help with coding sequence

Hello fellow Coders,

I am in need of your help!!!!

below you will find two sets of coding, one shows testing trends between 2019 and 2020 and one shows testing rates in 2019 by negative or positive results (because I am a new user, I am only allowed to display one image)

Now learning how to code and develop these types of visuals, I want to go a step further and look at only positive rates in 2019 / 2020.

I have by trying to figure out a way I can mesh the two codes together to do just that, but I have gotten no where.

I was wondering if anyone can assist me with this, I hope providing the coding structures you might be able to see how to wrangle something together and assist me with this.

I appreciate all of your help!

Thank you!

DF%>%
mutate(session_date = as.Date(session_date, format = "%m/%d/%Y"),
session_date_ym = as.yearmon(session_date)) %>%
count(session_date_ym) %>%
mutate(year = as.factor(year(session_date_ym))) %>%
ggplot(aes(month(session_date_ym, label = TRUE), n, color = year, group = year, linetype = year)) +
geom_line()+
geom_point()+
geom_text(aes(label = n), vjust = -0.5, color = "Black")+
scale_y_continuous(labels = scales::comma, limits = c(0,3300), expand = c(0,0), breaks = seq(0,3500,500))+
labs(x = "Months", y = "Frequency", title = "2019 / 2020 HIV Testing Rates by Month", subtitle = "Testing rates before and during COVID-19", caption = expression(paste("Data exported and provided by Aphirm")))+
theme(panel.grid = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_rect(color = "black", fill = NA))

image

DF %>%
mutate(Session.Date = as.Date(Session.Date, format = "%m/%d/%Y"),
session_date_yearmon = as.yearmon(Session.Date)) %>%
select(session_date_yearmon, Final.Test.Result) %>%
mutate(final_test_result_coded = case_when(
str_detect(str_to_lower(Final.Test.Result), ".pos.") ~ "Positive",
T ~ "Negative"
)) %>%
count(session_date_yearmon, final_test_result_coded) %>%
ggplot(aes(month(session_date_yearmon, label = TRUE), n, color = final_test_result_coded, group = final_test_result_coded))+
geom_line()+
geom_point()+
geom_text(aes(label = n), vjust = -0.4, color = "black")+
labs(x = "Months", y = "Frequency", title = "2019 HIV Testing Outcomes", subtitle = "HIV Testing Results",color = "Test Results", caption = expression(paste("Data exported and provided by Aphirm")))+
theme(panel.grid = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_rect(color = "black", fill = NA))

Can you please share a small part of the data set in a copy-paste friendly format?

In case you don't know how to do it, there are many options, which include:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link.

I appreciate you reaching. However, I found all I needed to do was simply add a filter function and below you will see it all worked out well!

Thank you!

Aphirm_2019_2020_HIV_Testing_Data %>%
mutate(Session.Date = as.Date(Session.Date, format = "%m/%d/%Y"),
session_date_ym = as.yearmon(Session.Date)) %>%
count(session_date_ym, final_test_result_coded) %>%
filter(final_test_result_coded == "Positive")%>%
mutate(year = as.factor(year(session_date_ym)))%>%
ggplot(aes(month(session_date_ym, label = TRUE), n, color = year, group = year, linetype = year)) +
geom_line()+
geom_text(aes(label = n), vjust = -0.1, color = "black")+
scale_y_continuous(limits = c(0,18), expand = c(0,0), breaks = seq(0,15,5))+
labs(x = "Months", y = "Frequency", title = "2019 / 2020 HIV Testing Positive Outcomes", subtitle = "Reactive Testing Results", caption = expression(paste("Data exported and provided by Aphirm")))+
theme(panel.grid = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_rect(color = "black", fill = NA))

image

Hello, I was wondering if I could ask you an additional question? The page wont allow me to make another post.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.