This is the fourth part in an ongoing series on how and why you should be using R, especially if you are a social science researcher or education researcher, like me. If you missed the earlier ones, you can check out part 1 (Intro to R), part 2 (R Basics), and part 3 (Data Cleaning and Manipulation). This post will go into some more specifics relating to data visualization.
There are many ways to visualize your data using R. By far the most popular (and I think robust and flexible) is using the ggplot2 package. This post will talk a bit about why and how to visualize your data and some tips and basics to using R’s ggplot2 package to help you achieve your visualization goals.
There are lots of reasons why you might want to visualize your data (or rather, why you should visualize your data). It can be a useful tool at various stages of research, and depending on where you are in your analysis process, different aspects of visualization might be more or less important to focus on. The way I see it, there are three main purposes for data visualization: examining your data, showing your data/findings, and sharing your data/findings.
What question are you trying to answer with your data? How can a visualization help you answer that? Do you have a really complex data set that is too hard to easily capture with a few numbers? Are you interested in variation and distribution rather than just means and medians? Are you exploring different relationships between variables and want to see how they interact?
2018 was a really hard year for me. So much changed in my life, the biggest of which might have been moving across the country to start my dream job as a professor at an R1 university. But in many ways, that huge change was overshadowed with another life-altering change: being diagnosed with diabetes.
Let’s go back a few years, to 2016 when I started feeling awful a lot more than should be normal. I use the word ‘awful’ because it was a fairly non-specific symptom for a long time. I was really tired and I had bouts of depression, but I mostly chalked this up to being stressed out with work and traveling a lot. I usually felt the worst right after a trip, so that seemed to make sense to me. So I told myself that in 2017 I would travel less and try to be less stressed out with work stuff. And I feel like I did those things (I definitely traveled a lot less and was generally less stressed with work-related things). But I felt even worse. My depressive episodes were worse and lasted longer than before. I was tired all of the time. Just had no energy. It was really frustrating.
Then, around November of 2017 things got really bad. I had some new symptoms: extreme thirst and unexplained weight loss. I lost 20 lbs in about six weeks even though I wasn’t eating any less or exercising any more. Something was clearly wrong. I had one really horrible weekend where I couldn’t get off the couch at all. So that following Monday afternoon (after I turned in a proposal at work) I went into urgent care to see what was going on. I’m not sure exactly what I was expecting, but mostly I just wanted to feel ‘not awful’ any more.
They ran some tests (actually a lot of tests) and had a clear answer: it was diabetes. Because my blood glucose (BG) was still fairly high (it was a bit above 300 mg/dL if I remember correctly), they transferred me to the emergency room so they could make sure it got down to a normal level. The doctors in the ER at Stanford Hospital were great and explained some of the basics to me. (Also, big thanks to my BFF Britte who was a huge help that day.) At the time, they weren’t sure what type of diabetes it was. They initially were leaning toward type 1, but they weren’t sure. After talking with some more doctors they decided to treat as if it were type 2 initially and see how that went. Type 2 can be managed (especially at early stages) with oral medications and a good diet and exericse plan. So that’s what I did.
A few weeks later I had a follow-up appointment with my regular doctor and based on some blood test results that there was some insulin in my system and me responding well to the oral meds, they concluded that it was most likely type 2. (Spoiler alert: it wasn’t. More on that later.)
I had a lot of mixed emotions around this time. First and foremost I was relieved that I had a diagnosis and that I could do something that would make me feel not awful all of the time. I was a bit scared about what this meant for my life long-term and overwhelmed by the types of adjustments I would need to make to stay healthy. But part of me was also upset at myself for “letting” this happen. It was difficult because, even though I’ve always been overweight, I always felt like I ate pretty healthy and exercised a decent amount. I explained this to the doctor that I was basically already doing all of the things they suggested I needed to do (w/r/t diet and exercise) to in order to keep it under control. Sure, I could eat a couple more salads and go for a couple more runs; but it wasn’t like I was sitting on the couch all day eating garbage. It was very frustrating, but I didn’t make a big fuss about it at the time.
I only told my family and a few close friends what was going on. Our society definitely has a stigma around type 2 diabetes and I felt like I didn’t want to bring on any unnecessary judgment onto myself. I felt like I could’ve done something differently to have prevented it and so I felt ashamed of my diagnoses and what it signified. This is obviously a huge problem and it makes me think about why it took me so long to go to the doctor when I had a good idea that was going to be the diagnosis (WebMD isn’t always wrong) and how many other people are out there living with feeling awful because they are ashamed. It’s not good.
Now of course, since I had just lost a bunch of weight, people were now constantly commenting to me about “how good I looked”. There was one exception where somebody asked me if I was “well” (and I think it’s relevant to point out that this person did not grow up in the United States), but everyone else wanted to me to know that I looked great now that I’d lost this weight and most of them then followed up with the question “how’d you do it?”. Every time this happened my stomach dropped a little bit. I wasn’t about to tell these people, most of whom were just acquaintances or work colleagues, my situation. And it was enough weight and obvious enough that I couldn’t pretend that I hadn’t noticed. So I responded with “low-carb diet” usually with some kind of either enthusiasm for how fun it is to limit your carb intake or like a resigned annoyance (accompanied with a shrug) that I don’t eat big bowls of pasta anymore. This explanation usually worked. I do feel a bit bad because, while it was not a lie that was I on a low-carb diet, my weight loss was a symptom of an untreated disease that was turning my life upside down and a low-carb diet was not really how I lost that weight. But then I remember that I don’t owe these people any information about my life and I don’t feel so bad. Also, stop asking people this question. Please. You don’t know someone’s life and there are many reasons someone could have lost a bunch of weight. And if someone loses a lot of weight very quickly, that is not healthy.
Through most of the first half of 2018 things were going pretty well. My numbers were in the range they needed to be and for the first time in a long time I felt relatively normal. My depression had almost entirely gone away and I had energy again. It was wonderful. It’s a good thing too because I was on the academic job market and I’m honestly not sure I would have been able to deal with that if I had still been ill. The timing worked out.
But then, in the summer, things started to slide a bit. My BG numbers were creeping up. At the time, I attributed this to all of the stress I was dealing with – planning a move from California to Illinois, tying up loose ends at my job, and lots of travel (including a big international conference). There were six weekends in a row from late May to early July where I was going somewhere. It was a lot. But I had most of July to recover before moving the first week of August and I thought it would be fine. It wasn’t.
By the beginning of October, I was fairly settled in my new job and location and I was doing really well with my diet and exercising a lot. I was riding my bike to my office every day and eating the healthiest I had ever eaten. And yet, my BG numbers were bad. And nothing I was doing was making them go down. It was extremely frustrating. I went to my new doctor and told him the situation. He ordered some tests and a follow-up visit in a month.
On my second visit when things hadn’t improved, he upped all of my meds and added a new one to help lower my BG. He also told me I wasn’t trying hard enough, which was not only not true but kind of a crappy thing to say to someone. I kind of pleaded with him that I had been doing everything I was supposed to, and I was started to lose weight again and it was really frustrating. Almost on a whim (he was literally about to walk out the door), he asked me if I was sure it was type 2. I said no and then, luckily, he referred me to the endocrinologist to make sure.
So, finally, in January of this year I got in to see the endocrinologist and she very quickly figured out that it was type 1. She ordered some tests just to make sure and started me on insulin. Sure enough, about a week later the tests confirmed that it was type 1. Since then, I’ve been feeling so much better. I give myself about 4 injections of insulin every day (one long-acting insulin once a day, and usually three shots of fast-acting insulin before meals). It’s been a huge adjustment but I’m figuring it out and learning a lot.
So why did this happen – the misdiagnosis and feeling good for a while and then bad again? Well, it turns out that when your pancreas decides to stop working, it doesn’t do it all at once. I’m in the “honeymoon” phase, where my pancreas is still producing a tiny bit of insulin, but it is tapering off and eventually (within a year or two, maybe sooner) it will stop completely. As that happens I will have to adjust the amount of insulin that I take to make up for it.
Type 1 and type 2 are actually very different and the only thing that really transferred across was my newly learned abilities in counting carbs (which I’m still getting better at). Type 1 is an autoimmune disease where your pancreas decides to stop producing insulin, which everyone needs to process the glucose in your body and turn it into energy. There is a genetic component, but it also just happens randomly (in something like 1% of the population). It used to be referred to as “juvenile diabetes” but that term isn’t really true (half of people with it are diagnosed after the age of 20). There is no cure and I will be dependent on insulin injections for the rest of my life. [Type 2 is when your body is resistant to the insulin that you are still producing. It also has a genetic component. It can usually be managed with diet, exercise, and oral medications and there is new evidence that it can be put into remission with certain amounts of weight loss. Some people with type 2 end up needing insulin as well.]
Data data data
There are so many numbers. And equations and ratios and graphs and trends. It’s a very good thing that I like all of those things and am good with numbers and doing math in my head. This would be a LOT harder if I didn’t. For example, before I eat anything, I need to: check and see what my current BG number is (a “normal” number should be between about 80 and 140), figure out if it’s going up or down or staying steady (this is currently a guess for me, but in the future it won’t be with a continuous glucose monitor), calculate the amount of carbs in what I’m about to eat (and also factor in the protein and fat and caffeine because those also has an effect on my BG), and decide whether or not I’m going to be exercising in the next 1-2 hours (exercise will generally lower my BG). Then, once I have that figured out I can give myself an injection of my fast-acting insulin that will balance out what I’m about to eat and keep my BG number in the normal range. If this sounds exhausting, you’re right! It is. And I have to do this multiple times a day, every day, for the rest of my life.
If my BG gets too high, I will feel super crappy and long-term high BG is associated with lots of adverse health outcomes and even death. If my BG gets too low, I could pass out or end up in a coma, which is obviously really bad as well. It’s important to keep my BG in range as much as possible.
There are many factors that can affect my blood sugar. Obviously food is the biggest one, but lots of other things make a difference as well. Exercise, hormones, the weather, and stress can all impact my BG number. Even if I eat the same thing every day, the numbers will be a bit different. Every day is a little experiment.
Soon (hopefully very soon), I will be adding a continuous glucose monitor (CGM) into my routine. Right now, in order to check my blood sugar, I have to prick my finger and use a test strip in a little device that I carry around to see what the number is. This is annoying because my fingers have become little pincushions, it takes a minute or so to do this every time, and I have to carry the pouch with the meter and supplies wherever I go if I want to do this (and, as I mentioned before, it’s good to do this before I eat anything or exercise and also at random points throughout the day). The CGM is a sensor and transmitter that I will insert/attach to my body once every 10 days or so and it will provide a blood glucose reading every 5 minutes directly to my smart phone (and watch). Amazing! This will make it so much easier to know what’s going on inside my body and how I’m reacting to the day. I will be able to see trends and do little experiments to better figure out my insulin to carb ratio and the right amount of long-acting insulin to take every day.
It’s really amazing that I’m alive. 100 years ago, type 1 diabetes was a death sentence. Then, in the 1920s, insulin was discovered and we were given a chance. The patent for producing insulin was sold to the University of Toronto for $1 so that everyone who needed it could have access to life-saving insulin. (Unfortunately, at least in the U.S., this equality of access is not a reality for many people so we still have some work to do. See below.)
It’s still fairly precarious as I need to carry around this little pen of insulin with me everywhere (I would probably not do well in a zombie apocalypse scenario), but I feel very thankful that I have a chance and, with good planning and control, I can still do pretty much whatever I want to do with my life. Hiking, soccer, and travel will still very much be a part of my life thanks to science and technology and I won’t ever forget that.
Why am I telling you this?
Well, it’s a huge, constant part of my life now and it feels weird to hide it (and I don’t want to hide it). But, really, for at least two reasons. One is that type 1 diabetes is a lot to manage. It is a 24/7 job for me to manage my blood sugars, count the carbs in whatever I’m eating, inject the right amount of insulin at the right time, and not get too discouraged or upset when the numbers get a bit unpredictable (because they will; it is the nature of this that I won’t be able to control it perfectly all of the time). And I need help from my friends and family to support me through this.
If we’re hanging out together, I need you to: not be alarmed when I give myself an injection; know what it means if I’m “low” and how to help me get some sugar into my system; understand that I might check my phone/watch a lot (I’m likely looking at my blood sugar numbers). If you’re not physically close by (or even if you are), I need you to: be there to listen if I’m having one of those days when it just feels like too much and I need to vent and to advocate for a better healthcare system in the U.S. so that people don’t have to ration their insulin because they can’t afford it.
The other reason is that this is a fairly “invisible” disease. You usually can’t tell that someone has it by looking at them (unless their CGM or pump is visible, and even then you might not know what those are for). Before my diagnosis, the only people I knew with type 1 diabetes were Dawn from the Babysitter’s Club books, the Julia Roberts character in Steel Magnolias, and one of my friend’s boyfriends in college. None of whom really taught me much about what the day-to-day would be like for this. So, I had a lot of learning to do fairly quickly. I also didn’t understand the situation with the affordability of insulin in the United States and how so many people are having to spend exorbitant amounts of money just to stay alive. To be clear, for me and other type 1 diabetics, insulin is not so much a medication as it is like oxygen; without it we will die. The fact that insurance companies and pharmaceutical manufacturers are allowed to make a profit on something that I need to stay alive makes me really angry. It costs the manufacturers about $5/vial to make insulin, the “modern” version of which has been around for about two decades and hasn’t changed in form or delivery nearly at all in that time, and yet they can charge hundreds of dollars for it (or more). The price has more than tripled in the last two decades. I have a good job and good insurance and it still costs me about $100/month for my insulin and other supplies I need (it will be more once I get my CGM). Other countries have either free insulin for people who need it or a much lower cost (something closer to $5-10/vial), so this is clearly achievable if we try.
Anyway, I’m here trying to live my best life despite this extra hassle. Your support and understanding and advocacy are much appreciated.
This is the third part in an ongoing series on how and why you should be using R. If you missed the earlier ones, you can check out part 1 (Intro to R) and part 2 (R Basics). This post will go into some more specifics relating to data cleaning, organization, and manipulation.
In my opinion, the dplyr package is a game changer for those trying to learn R. It is what motivated me from just recommending that people use R to basically demanding that my friends and co-workers switch to R. I remember the day that I finally got around to learning how to use the package’s functionality and all of the ways in which it lets you easily and clearly manipulate your data frames1. I just kind of stared at my computer screen and imagined how much better my data-life was going to be with these tools. I realized that the hours and hours I used to spend in Excel trying to massage my data into the right form were over2. Also, I wouldn’t have to decipher weird R base code anymore when trying to create new variables or filter datasets. The dplyr package and its friends make your code/scripts much easier to read which will help both you and future you in trying to decipher what is going on.
In August I moved across the country (again) for a new opportunity that I am so excited about. I have started a new position as a tenure-track assistant professor at the University of Illinois at Urbana-Champaign. Yay! I am part of a new campus-level initiative called Technology Innovation in Educational Research and Design (or TIER-ED). I have a split appointment within the College of Education; I have a 75% appointment in the Educational Psychology department and 25% in the Curriculum and Instruction department. The plan is to do a lot of interdisciplinary work across campus (e.g., with VR/AR researchers, speech researchers, and the physics department).
I have been on twitter for almost ten years. Twitter has changed a lot in that time and my enthusiasm for the platform has waned a bit over the years, but I still find it to be a compelling communication platform. Initially I used it to share about the more mundane, personal parts of life and my stresses as I finished graduate school. Lately it’s become more professionally-focused (most of the time) and more reflective of the many things that are happening in the world (but with important dog pictures also). I have met lots of people through twitter as well as listened and learned from thousands of people who I would never have met in my day-to-day life. It has helped me gain a wider audience for my academic work and has allowed me to share pictures of my awesome dog with strangers and friends alike.
I just hit 10,000 tweets (if I did this correctly then the tweet linking to this post would be number 10,000). And I thought it would be a good opportunity for me to go back through my twitter archive and get a sense of what all of those tweets were about and how I tweeted. (The analysis that follows is actually only on my first 9,945 tweets because I had to request my tweets a couple weeks ago and do the actual analysis.) This was also a fun R exercise for me1.
Yesterday I posted some videos on Instagram of step-by-step instructions on how to build your own pinhole projector to safely view the eclipse on August 21st. In order to make the instructions easier to share, I’ve compiled them all here (well, screenshots from them at least) to help you turn an ordinary cardboard box into a pinhole projector.