Week 12: Creating an R Markdown File for Alignment Score Visualization
Getting Started
At first, R Markdown felt a bit confusing because it combines text and code in one file. But once I understood the structure, it became clear how powerful it is. The key was using code chunks, which are sections of the file that run the R code. Each chunk starts with ```{r}
and ends with ```
.
For my project, I wanted to display alignment scores for V and J regions in a table and a bar chart. Writing and organizing the code into chunks made it easy to run and test each part.
Challenges I Faced
Code Showing as Plain Text:
When I first tried knitting the file, the HTML output only showed the code as plain text. I realized this was because I had included everything in thesetup
chunk, which is only for settings. Separating the data and visualization code into their own chunks fixed this.
Troubleshooting Errors:
Debugging code in R Markdown was tricky because knitting stops when there’s an error. To fix this, I ran each chunk one by one in RStudio before knitting the whole file. This made it easier to find and fix mistakes.Deciding What to Show:
I learned that I could control whether the code or just the results showed up in the final document. For the table, I wanted both the code and output to show, so I usedecho = TRUE
. For the bar chart, I hid the code (echo = FALSE
) so the focus was on the visualization.
What I Learned
R Markdown Is Powerful:
It’s a great tool for combining text, code, and results in one document. It makes it easy to share your work in a clear and professional way.The Importance of Code Chunks:
Properly setting up code chunks is key. Using options likeecho
,eval
, andinclude
helped me decide what to show in the final file.Data Visualization with ggplot2:
Creating the bar chart withggplot2
was simple and fun. I learned how to make clear, customizable visualizations that look professional.
Reflection
I’m pretty happy with how this project turned out. It showed me how useful R Markdown is for combining analysis, text, and visuals. In the future, I plan to use R Markdown for more projects, try new output formats like PDF, and even add interactive visualizations.
If you’re new to R Markdown, I recommend starting with a small project like this. It’s a great way to learn how to present your work effectively.
For a more detailed exploration visit my GitHub repository
Comments
Post a Comment