After importing the data, untidy columns and rows were fixed and renamed again. Meaningless row was deleted. [1-3]
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.5.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(readxl)
## Warning: package 'readxl' was built under R version 4.5.3
figure6 <- read_excel("Figure 6 Source data.xlsx", sheet = "Figure 6f")
## New names:
## • `` -> `...2`
## • `` -> `...3`
colnames(figure6) <- c("Trials", "Vehicle", "CTPI2")
figure6 <- figure6[-1, ]
When examination of data was completed , data was ready for reproducing figure 6f.
dim(figure6)
## [1] 10 3
str(figure6)
## tibble [10 × 3] (S3: tbl_df/tbl/data.frame)
## $ Trials : chr [1:10] "Trial 1" "Trial 2" "Trial 3" "Trial 4" ...
## $ Vehicle: chr [1:10] "0" "0" "0" "5.2631579999999998" ...
## $ CTPI2 : chr [1:10] "0" "5" "20" "25" ...
head(figure6)
## # A tibble: 6 × 3
## Trials Vehicle CTPI2
## <chr> <chr> <chr>
## 1 Trial 1 0 0
## 2 Trial 2 0 5
## 3 Trial 3 0 20
## 4 Trial 4 5.2631579999999998 25
## 5 Trial 5 5.2631579999999998 35
## 6 Trial 6 15.78947 55
is.na(figure6)
## Trials Vehicle CTPI2
## [1,] FALSE FALSE FALSE
## [2,] FALSE FALSE FALSE
## [3,] FALSE FALSE FALSE
## [4,] FALSE FALSE FALSE
## [5,] FALSE FALSE FALSE
## [6,] FALSE FALSE FALSE
## [7,] FALSE FALSE FALSE
## [8,] FALSE FALSE FALSE
## [9,] FALSE FALSE FALSE
## [10,] FALSE FALSE FALSE
when the figure was first plotted , x axis ticks labels such as Trial 1 were not on the x axis sequentially then “factor” was used for sorting trials. Structure of vehicle and CTPI2 were changed to numeric from character. Then The figure was reproduced to best resemble the original. Attention was paid to some point ; limits of axis, sorting Trials, arrangement of line width and point size properly, angle of x axis labels, removal of grids , editing title and legend. Also, in the beginning of plotting code “group = 1” is used because trials were factor structure so plot line could not be drawn , it was necessary to tell ggplot2 that it should treat all trials as part of the same group. In addition, the data were obtained from the official Nature source-data workbook “Figure 6 Source data.xlsx”, using the sheet “Figure 6f”. [4-12]
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.3
figure6$Trials <- factor(figure6$Trials, levels = c("Trial 1", "Trial 2", "Trial 3", "Trial 4", "Trial 5","Trial 6", "Trial 7", "Trial 8", "Trial 9", "Trial 10"))
str(figure6)
## tibble [10 × 3] (S3: tbl_df/tbl/data.frame)
## $ Trials : Factor w/ 10 levels "Trial 1","Trial 2",..: 1 2 3 4 5 6 7 8 9 10
## $ Vehicle: chr [1:10] "0" "0" "0" "5.2631579999999998" ...
## $ CTPI2 : chr [1:10] "0" "5" "20" "25" ...
figure6$Vehicle <- as.numeric(figure6$Vehicle)
figure6$CTPI2 <- as.numeric(figure6$CTPI2)
fig6f<- ggplot(data = figure6, mapping = aes(x= Trials, group = 1))+
geom_point(aes(y = Vehicle, color = "vehicle", size = "size"))+
geom_line(aes(y = Vehicle, linewidth = "lw", color = "vehicle")) +
geom_point(aes(y = CTPI2, size = "size", color = "CTPI2"))+
geom_line(aes(y = CTPI2, linewidth = "lw", color = "CTPI2"))+
scale_y_continuous(limits = c(0,100), breaks = seq(0,100, by = 20), expand = c(0.004,0))+
scale_color_manual(values = c("vehicle"="black", "CTPI2" = "green"))+
scale_linewidth_manual(values = c("lw"=0.5))+
scale_size_manual(values = c("size"= 3))+
labs(title = "f", x= "Trials", y = "Percentage of mice hanging 90 s (hanging test)")+
guides(size = FALSE, linewidth = FALSE) +
theme_minimal()+
theme(axis.text.x = element_text(angle = 45)) +
theme(panel.grid.minor = element_blank(), panel.grid.major = element_blank(), axis.line = element_line(color = "black"), axis.ticks = element_line(color = "black"))+
theme(plot.title = element_text(size = 15, face = "bold")) +
theme(legend.position = "inside",
legend.position.inside = c(0.15,0.85))
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
print(fig6f)
ggsave("figure6f/fig6f.pdf")
## Saving 7 x 5 in image
1- https://campus.datacamp.com/courses/introduction-to-importing-data-in-r/importing-excel-data?ex=3 2- https://stackoverflow.com/questions/6081439/changing-column-names-of-a-data-frame 3- https://www.youtube.com/watch?v=JISBGZIpyFI 4- https://forum.posit.co/t/how-to-order-and-visualize-x-axis-variables-in-ggplot2/163390 5- https://www.youtube.com/watch?v=2byZx6hz87Y 6- https://stackoverflow.com/questions/22818899/setting-y-axis-breaks-in-ggplot 7- https://www.datanovia.com/learn/data-visualization/ggplot2/axis-ticks 8- https://www.reddit.com/r/RStudio/comments/wwhm52/ggplot_graphs_cant_make_lineplot/ 9- https://www.youtube.com/watch?v=RdjKuK938Qs 10- https://www.geeksforgeeks.org/r-language/remove-legend-in-ggplot2-in-r/ 11- https://r-statistics.co/ggplot2-Legends-in-R.html 12- https://r-statistics.co/ggplot2-element_line-in-R.html