Skip to content

Commit

Permalink
shiny fix issue on measured distance vs requested distance plot
Browse files Browse the repository at this point in the history
  • Loading branch information
simonliao98 committed Jan 11, 2025
1 parent 4e288d2 commit 08c041b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions plotting/distancePlot.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
get_measured_distance_data <- function(data_list) {
print('inside get_measured_distance_data')
df <- tibble()
for (i in 1:length(data_list)) {
t <- data_list[[i]] %>%
Expand All @@ -17,31 +18,34 @@ get_measured_distance_data <- function(data_list) {
df <- rbind(df, tmp)
}
}

print('done get_measured_distance_data')
return(df)
}


plot_distance <- function(data_list) {
print('inside plot_distance')
distance <- get_measured_distance_data(data_list)

if (nrow(distance) == 0) {
return(NULL)
}
distance <- distance %>% mutate(calibrateTrackDistanceMeasuredCm = as.numeric(calibrateTrackDistanceMeasuredCm),
calibrateTrackDistanceRequestedCm = as.numeric(calibrateTrackDistanceRequestedCm))
fit <- lm(calibrateTrackDistanceMeasuredCm~calibrateTrackDistanceRequestedCm, data = distance)

print(fit)
slope <- coef(fit)
slope <- format(round(slope[['calibrateTrackDistanceRequestedCm']],2),nsmall=2)
corr <- cor(distance$calibrateTrackDistanceRequestedCm, distance$calibrateTrackDistanceMeasuredCm)
corr <- format(round(corr,2),nsmall=2)
p <- ggplot() +
geom_point(data=distance, aes(x = calibrateTrackDistanceRequestedCm, y = calibrateTrackDistanceMeasuredCm)) +
p <- ggplot(data=distance, aes(x = calibrateTrackDistanceRequestedCm, y = calibrateTrackDistanceMeasuredCm)) +
geom_point() +
ggpp::geom_text_npc(aes(npcx="left",
npcy="top"),
label = paste0('N=',nrow(distance),'\n',
'R=',corr,'\n',
'slope=',slope)) +
geom_smooth(method='lm',
se=F)
geom_smooth(method='lm',se=F) +
labs(title = 'measured distance (cm) vs requested\ndistance (cm)')
return(p)
}

0 comments on commit 08c041b

Please sign in to comment.