using a variable with scatter plt

Trying to learn how to plot using this data set
CHN_NAME LOC_NAME HIST_DATE LATENCY_HRS
1 cp_cust tngpp 4/22/2020 1.02
2 cp_geam tngpp 4/22/2020 1.33
3 cp_wip tngpp 4/22/2020 5.25
4 cp_xla_ods tncpp 4/22/2020 1.09
5 hvr_job_c002 tntap 4/22/2020 1.04
6 khw_fin_c4 tngpp 4/22/2020 5.94

this works fine
plot(data$LATENCY_HRS,
main = "Latency Times",
xlab = "ytd",
ylab = "Time")

now trying to add variable to only plot data based on a specific loc_name such as

with 'data$LOC_NAME==("tngpp")',
scatter.smooth(x=data$LATENCY_HRS,
main="target ~ Latency")

and keep hitting a roadblock .. simply want to only ploy latency_hrs based on a specific loc_name

Regards
Tom

FYI I am a complete new r user and any help is appreciated

Here are three ways to make a subset of a data frame

data[data$LOC_NAME == "tngpp", ]

subset(data, LOC_NAME == "tngpp"]

library(dplyr)
filter(data, LOC_NAME == "tngpp")

Personally, I would do the subsetting in a separate step, storing the result in a variable, and plot that.

thanx

filter(data, LOC_NAME == "tncpp")
scatter.smooth(x=data$LATENCY_HRS,
main="target ~ Latency")

works great

add on question ..
subset(data, LOC_NAME == "tngpp")
scatter.smooth(x=data$LATENCY_HRS,
xlab='Target Volume', ylab = 'Latency in Hrs',
main='Target - Latency')

works too but the plot shows all of the data and not just the subset or filtered data. The correct data entries show in the console but not the plot

sorry for all the newbie questions and hope this is the correct place to ask them
Tom

You have to store the result of the subset function in a variable and use that in scatter.smooth.

SubSetOfData <- subset(data, LOC_NAME == "tngpp")
scatter.smooth(x= SubSetOfData$LATENCY_HRS,
xlab='Target Volume', ylab = 'Latency in Hrs',
main='Target - Latency')

The same would apply to the use of the filter() function from dplyr.

thank you :grinning: