<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Athena Chapekis on Medium]]></title>
        <description><![CDATA[Stories by Athena Chapekis on Medium]]></description>
        <link>https://medium.com/@achapekis?source=rss-867b113f8ff0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ByAPZPfgHspPElI4RGq7ig.png</url>
            <title>Stories by Athena Chapekis on Medium</title>
            <link>https://medium.com/@achapekis?source=rss-867b113f8ff0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:16:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@achapekis/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating a custom graphics package in R using ggplot2]]></title>
            <link>https://medium.com/pew-research-center-decoded/creating-a-custom-graphics-package-in-r-using-ggplot2-3b0f7e8a32af?source=rss-867b113f8ff0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b0f7e8a32af</guid>
            <category><![CDATA[dataviz]]></category>
            <category><![CDATA[ggplot2]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[graphic-design]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Athena Chapekis]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 17:30:38 GMT</pubDate>
            <atom:updated>2022-10-04T17:30:38.028Z</atom:updated>
            <content:encoded><![CDATA[<h3>What we learned from creating a custom graphics package in R using ggplot2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-q7rJ3W-rsaNZckUcyiu3Q.png" /><figcaption>(Pew Research Center illustration)</figcaption></figure><p>Creating informative and digestible data visualizations is a foundational aspect of Pew Research Center’s work. Traditionally, our report graphics have been generated by individual researchers using a custom Excel template developed by our design team, or on an ad hoc basis by graphic designers using professional tools and mock-up designs.</p><p>In recent years, many of our researchers have expressed an interest in using R as an integrated environment for data analysis and graphics development. R allows users to generate iterative graphics directly from analysis scripts, which is helpful for quickly evaluating different ways to visualize results and findings.</p><p>However, the standard graphics libraries in R look quite different from Pew Research Center’s in-house style. As a result, our R users typically had two options: produce graphics directly in R that would need extensive reworking prior to publication or leave the R environment entirely in order to create stylistically appropriate visualizations.</p><p>To address this, some of our researchers started developing custom versions of Pew-style graphics using <a href="https://ggplot2.tidyverse.org/">ggplot2</a>, a complex yet highly customizable data visualization tool in the <a href="https://www.tidyverse.org/">tidyverse</a> suite for R. But with multiple researchers developing their own solutions — often in personal folders, and by copy-and-pasting from other projects — errors and inconsistencies accumulated.</p><p>In an effort to solve some of these issues, we set out to develop a Pew Research Center-specific custom R package containing all of the standard graphics functions we use in our work in one easy-to-install package — similar to what a number of <a href="https://rdrr.io/cran/ggthemes/">other research and journalism organizations</a> have done. Our main goal was to create a package that allows researchers to quickly iterate between different data visualizations that are consistent with Pew style.</p><p>Our package, which we refer to internally as “pewplots,” is a ggplot2 wrapper made up of customized versions of existing ggplot2 functions. In practice, this means that ggplot2 plotting functions are <em>wrapped </em>within pewplots functions, and code is added or modified to extend the functionality of the original plotting function.</p><figure><img alt="Side-by-side comparisons of the same bar chart made with ggplot2 and pewplots and the same line chart made with ggplot2 and pewplots." src="https://cdn-images-1.medium.com/max/972/1*qysK5VIFSGY6MB9NAf4RDQ.png" /></figure><p>In addition to ensuring that every R developer is using the same official style, we also hoped this package would make data visualization in R more user-friendly for those who are newer to programming or coding. Making wrappers for ggplot2 functions does require a fair amount of technical know-how. But once complete, wrapper functions like this take much of the complexity off of individual users’ plates and make plot generation standardized, faster and more accessible.</p><p>We developed and continue to manage the code with the help of <a href="https://happygitwithr.com/big-picture.html">GitHub</a> and <a href="https://www.ibm.com/garage/method/practices/deliver/tool_nexus/">Nexus</a> repositories, which allow us to work collaboratively and make the package directly accessible to any R user on our internal server.</p><p>But beyond the technical details, what are the pros and cons of an effort like this? From our experience, we have a few takeaways and tips if you want to try something like this yourself.</p><h3><strong>Things to consider before you begin, and tips for development</strong></h3><p>These are some decisions we made early in the process that helped keep us on track, as well as some more general tips for development. We’d recommend spending some time on these issues before you start — as it’ll help you save time and stress down the line — and keeping them in mind throughout the development process.</p><p><strong>Determine if a custom graphics package is the right solution for you. </strong>The biggest question in this process is probably whether the time needed to put together a custom graphics package is worth it. Ask yourself why having custom plotting functions in a package would be useful to you or your organization.</p><p>If you’re primarily working with your data in R, it can be a hassle to switch between R and some other graphics generation program (Excel, Tableau, etc.). But if you’re able to make your graphics directly in R, there’s no need to worry about exporting data, making sure that data is always up to date, or switching between applications. Also, if there’s a specific style guide for your graphics that you’re trying to follow, existing ggplot2 graphics are unlikely to tick all the boxes you need. If this sounds like your circumstances, a custom package might be a good option for you.</p><p>A custom package might also be a good solution for you if you’re interested in automation. Having plots and plot features built into custom functions automates a lot of nuance and details in specifying plot aesthetics and alignment. Instead of having the same 20 lines of code copied and pasted, with numerous detail adjustments in your analysis 10 separate times, you can use functions to store most of the redundant information. It’s also useful in case you have multiple people making graphics and you want to standardize those graphics across users.</p><p><strong>Establish a baseline for what you want it to accomplish. </strong>Do you want only a theme, or do you want fully customized plot types? How much detail do you want to be default behavior, as opposed to the responsibility of the user?</p><p>One of the most important steps in the process is to figure out what features you need to include so your custom graphics package does what its users need and want it to do. At some point, it’s necessary to settle on a set of features you want to include to give yourself a goal, as well as a stopping point. There will probably always be more features you can add, but if you don’t determine the baseline of what you want to include, you might find yourself adding features but working toward no specific goal.</p><p><strong>Decide if you want an internal or external release. </strong>The main question you want to ask here is <em>whether you want to commit to code maintenance and development for external users. </em>At Pew Research Center, we decided to keep our package for internal use only. It’s extremely beneficial to our workflows but isn’t necessarily something we’re interested in maintaining for external use, as we do with some of <a href="https://github.com/pewresearch/pewmethods">our other packages</a>. That decision influenced how we designed our vignettes and other documentation, as well as the naming conventions used for many of the functions and colors/color palettes.</p><p><strong>Get feedback from the people who will be using the package. </strong>While certain things may make sense to you as the developer, the most important thing is that the people that you’re making the package for are able to use it. User feedback is important for any product or service, and this is no different. Also, getting feedback from people who aren’t part of the development process can bring in new perspectives and help you catch things that you, as the developer, may not have noticed or considered. In our development process, it was especially important to get feedback from our design director to make sure that our graphics were up to par. Asking end users to test out the package allowed us to catch missing features and unclear documentation.</p><p><strong>Test a <em>lot. </em></strong>If you want your package to be flexible and versatile, you should test it on as many different data sources as possible<em>.</em> You might not even notice a feature is missing or broken until you’ve tested it on a specific data source or trying to make a specific kind of plot.</p><h3><strong>Challenges and pitfalls to watch for</strong></h3><p>Despite the benefits we’ve seen from creating our custom graphics package, our effort has not been without challenges.</p><p>Most significantly, we realized that an effort of this scale takes a lot of time and work. We developed v1.0.0 of pewplots over a period of around six months of consistent work. There’s also a relatively high barrier of entry. Just to begin, you need a fairly high level of general R knowledge, as well as knowledge about the tidyverse and ggplot2 more specifically.</p><p>In our case, it was also necessary for developers and researchers to be familiar with the ins and outs of Pew Research Center’s official style guide for graphics. In addition, the process required a decent understanding of the graphics that different teams within the Center make, including the different features and customizations those teams require.</p><p>All of that is to say that there is a gap between generating R graphics that complement our internal analysis and workflows and generating R graphics that are publication-ready. There are also still countless features we could add in terms of tweaks and customizations. One key consideration in the future evolution of our internal graphics package is distinguishing between features that we <em>need</em> to have — as opposed to ones that are <em>nice</em> to have — and generally preventing “scope creep” as we move forward.</p><p><em>Athena Chapekis is a data science analyst at Pew Research Center.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b0f7e8a32af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pew-research-center-decoded/creating-a-custom-graphics-package-in-r-using-ggplot2-3b0f7e8a32af">Creating a custom graphics package in R using ggplot2</a> was originally published in <a href="https://medium.com/pew-research-center-decoded">Pew Research Center: Decoded</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evaluating changes in how we ask Americans for their Twitter profiles]]></title>
            <link>https://medium.com/pew-research-center-decoded/evaluating-changes-in-how-we-ask-americans-for-their-twitter-profiles-8bf5b36d1bdd?source=rss-867b113f8ff0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bf5b36d1bdd</guid>
            <category><![CDATA[survey-research]]></category>
            <category><![CDATA[surveys]]></category>
            <category><![CDATA[polling]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[research-methods]]></category>
            <dc:creator><![CDATA[Athena Chapekis]]></dc:creator>
            <pubDate>Wed, 31 Aug 2022 14:56:46 GMT</pubDate>
            <atom:updated>2022-08-31T14:56:46.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xVrOiWe69AQgOyDIjZuYbw.png" /><figcaption>(Pew Research Center illustration)</figcaption></figure><p>Starting in 2019 and again in 2021, Pew Research Center has asked members of our nationally representative online survey panel, the <a href="https://www.pewresearch.org/our-methods/u-s-surveys/the-american-trends-panel/">American Trends Panel</a>, if they use Twitter and, if so, whether they would be willing to provide us with their Twitter handles for research purposes. This has allowed us to study how U.S. adult Twitter users’ stated attitudes and opinions on a variety of topics correspond to their actual behaviors on the platform.</p><p>As with any survey question, the wording of an “ask” like this can <a href="https://doi.org/10.1093/ijpor/edv006">affect how it is perceived and understood</a> by the respondents taking the survey. In our March 2021 survey, we decided to take a fresh look at the consent language we used when asking Americans to give us their Twitter handles. Below is the original question wording.</p><blockquote>We would like to better understand the role of Twitter in society; for example, how often people use Twitter and what they tweet about. To help us with this research, we hope you will share your Twitter handle with us. Your handle is the username you have selected for your Twitter account (like @yourhandle). We will treat your handle with the same care we take with all of your survey responses — it will be used only for research purposes, and we will never share any of your tweets or any profile data that can be linked back to you. We expect that this research will be concluded within 18 months.</blockquote><blockquote>Please list your Twitter handle in the box below.</blockquote><blockquote>[MEDIUM TEXT BOX WITH @ IN FRONT OF THE TEXT BOX]</blockquote><blockquote>[Twitter handles in box: 1) cannot contain ‘Twitter’ or ‘Admin’, 2) Cannot be longer than 15 characters, 3) only alphanumeric characters (A-Z, 0–9) and underscores are allowed. Capitalization doesn’t matter.]</blockquote><blockquote>SHOW ON SEPARATE SCREEN IF TWITTER HANDLE GIVEN (TWITTER2=VALID TWITTER HANDLE ENTERED):</blockquote><blockquote>If at any point you wish to opt out of research related to your Twitter account, contact info@americantrendspanel.org. For more information about our privacy practices, please see our Privacy Policy.</blockquote><p>The original language we used in our 2019 survey had the benefit of being simple and readable — perhaps overly so. It wasn’t entirely clear, for instance, what information we would actually be getting from people’s Twitter accounts.</p><p>When we revised our question wording in 2021, we first wanted to give more details to our panelists before they consented. That meant describing as clearly as possible — within the constraints of our existing survey design practices — what information we would and would not get from them, what we would do with that information and how long we would continue our research project. We also wanted to make sure we conveyed all of this information without using unnecessary technical jargon and that we kept the text at a relatively simple reading level.</p><p>In addition to these changes, we tried using a “loss framing” to describe why we wanted respondents’ Twitter handles. That is, rather than describing what we <em>would</em> be able to do if they gave<em> </em>us their information — as we had done in our first effort — we described the research we would <em>not</em> be able to conduct unless they gave us a handle. This change was motivated by evidence that emphasizing negative effects of nonconsent is <a href="https://doi.org/10.1093/ijpor/edv006">a more effective motivator</a> for survey respondents than emphasizing the benefits of consenting, at least when it comes to asking for permission to link survey responses to external data.</p><p>The updated question wording, with changes and additions in bold text, is here:</p><blockquote>In many of our surveys, we ask about how people like you use social media. But there’s a lot we cannot learn unless you allow us to connect information about your public Twitter behavior to your answers.</blockquote><blockquote>No matter how often you use Twitter, would you be willing to share your Twitter handle to help us with this research?</blockquote><blockquote>1 Yes</blockquote><blockquote>2 No</blockquote><blockquote>This project will ONLY collect information that an ordinary user would see when they visit your profile (see here [POPUP] for more details). We will treat this data just like we treat your survey responses and will NEVER share anything that can be linked back to you.</blockquote><blockquote><strong>[POPUP]</strong></blockquote><blockquote><strong>How we will use your Twitter handle</strong></blockquote><blockquote><strong>If you provide us with your Twitter handle, we will only be able to collect what an ordinary user would see when visiting your profile. The specific information we will have access to depends on the privacy settings of your Twitter account.</strong></blockquote><blockquote><strong>If your account is set to PUBLIC, we will be able to see the accounts you follow; the accounts that follow you; the text of any tweets you have posted; the basic information in your profile, such as your description and the age of your account. We will NOT have access to any private messages you have sent or received.</strong></blockquote><blockquote><strong>If your account is set to PRIVATE, we will be able to see how many accounts you follow or how many times you have tweeted — but will NOT be able to see any private messages you have sent or received; the actual content of your tweets; or the names of the accounts you follow or that follow you.</strong></blockquote><blockquote>We expect that this research will be concluded in approximately 18 months. <strong>At that point we will ask you again whether or not you would like to provide your handle. If you provided your Twitter handle to us previously, that is why you are seeing this question again.</strong></blockquote><blockquote><strong>If at any point you wish to opt out of research related to your Twitter account, contact info@americantrendspanel.org. For more information about our privacy practices, please see our Privacy Policy.</strong></blockquote><blockquote><strong>[END POPUP]</strong></blockquote><blockquote>Please list your Twitter handle in the box below. Your handle is the username you selected for your Twitter account. <strong>It is no more than 15 characters long and looks like @yourhandle.</strong></blockquote><blockquote>[MEDIUM TEXT BOX WITH @ IN FRONT OF THE TEXT BOX]</blockquote><blockquote>[PROGRAMMING NOTE: Twitter handles in box: 1) cannot contain ‘Twitter’ or ‘Admin’, 2) Cannot be longer than 15 characters (do not display character limit on screen), 3) only alphanumeric characters (A-Z, 0–9) and underscores are allowed. Capitalization doesn’t matter.]</blockquote><blockquote>Text for prompt when invalid response is entered: Answer is not valid. Your handle can only include alphanumeric characters (A-Z and 0–9) and underscores.</blockquote><h3><strong>Assessing the results of our revised question wording</strong></h3><p>So how did response patterns change after we revised our question wording?</p><p>In some areas, we saw improvements. In our 2019 survey, for example, around one-in-ten volunteered Twitter handles (11%) were deemed invalid because the account did not exist, the basic demographics of the account obviously contradicted their survey responses, or for some other reason. The percentage of invalid handles was only 6% in 2021.</p><p>But while a slightly larger share of handles were valid this time around, a <em>lower</em> overall share of Twitter users were willing to provide us with their handles in the first place. In our 2019 survey, 21% of our panelists reported being Twitter users and 59% of them provided a handle of any type. In our 2021 survey, a similar share (22%) reported being Twitter users — but just 43% of them provided us with a handle.</p><p>After accounting for the differences in handle quality noted above, the total share of Twitter users who provided a valid handle was 53% in 2019 and 40% in 2021.</p><h3><strong>What explains the lower consent rate?</strong></h3><p>Increased participation was <em>not</em> the primary reason we changed our consent language in 2021. Still, we had hoped that our adjustments might encourage more respondents to offer us their handles. So why did the opposite occur?</p><p>Unfortunately, due to sample size limitations, we didn’t have the option of experimentally testing different versions of the consent question. We could only evaluate one question fielded in 2019 and a different one fielded in 2021. As a result, we couldn’t really tell how much of the decline in the consent rate was due to the question itself, to the changing composition of the American Trends Panel (which regularly gets “refreshed”) or to other external factors.</p><p>To try to shed more light on this question, we looked at the 2,644 Twitter users in our 2021 survey and examined whether they participated in the 2019 survey, too. By focusing on the individuals who responded to both surveys, we thought we might be able to discover factors <em>other</em> than question wording that may have influenced their decision to consent.</p><figure><img alt="A table displaying the proportions of Twitter users who provided a handle in 2021 based on their panel status in 2019. Most Twitter users who volunteered their handles in 2019 did so again in 2021." src="https://cdn-images-1.medium.com/max/1024/1*vChvaUfobajTclcViyvhfw.png" /></figure><p>We learned a few things from this analysis. For one, people who received the question for a second time tended to respond the same way they did the first time around. It also turned out that we were able to convince a sizable share of panelists who were unwilling to share their Twitter handles in 2019 to do so in 2021–16% of them, to be exact. That group, however, was offset by “losses” from people who did give us a handle the first time around but declined to do so in 2021. Around 35% of this cohort declined to provide us a handle in 2021 after doing so two years earlier.</p><p>We also found that respondents who saw the consent question for the first time in 2021 — either because they were new to the American Trends Panel or because they were existing panelists who were not Twitter users in 2019 — consented at lower rates than we saw in our first effort.</p><p>To investigate further, we decided to look more closely at respondents who received the question in both 2019 and 2021 to try to find other patterns. First, we divided those respondents into two groups: those who consented in 2019 and those who declined in 2019. We then looked to see if there were any demographic or behavioral factors that were associated with agreeing to provide a Twitter handle in 2021.</p><p>Overall, there were few substantive differences between these groups by race, gender, age or party identification. The significant differences that did exist often told unclear or even contradictory stories. In the case of privacy attitudes, for instance, panelists who provided us with Twitter handles in 2019 were more likely to consent again in 2021 if they believed that only a few people see their tweets. However, this group was <em>also</em> more likely to consent again if they believed that it would be easy to identify their social or political views based on the content of their Twitter account or said that they use Twitter primarily to express their own opinions rather than see the views of others.</p><p>Similarly, panelists who did not provide a handle in 2019 were less likely to consent in 2021 if they viewed harassment on Twitter as a problem. But for respondents who did give a handle in 2019, there was no relation between their views of harassment on Twitter and their willingness to provide a handle in the subsequent ask.</p><p>In the end, it’s a bit of a mystery why our changes in question wording resulted in a lower consent rate in 2021.</p><h3><strong>Takeaways</strong></h3><p>Every respondent in a survey is important, and it’s always unfortunate to “lose” someone. That’s especially true when you’re recruiting from a relatively small pool to begin with, as is the case with Twitter users.</p><p>At the same time, we know the Twitter users who provided us with a handle in 2021 are still largely representative of Twitter users more broadly — especially after we weight the sample appropriately, as we discuss in <a href="https://medium.com/pew-research-center-decoded/how-we-created-a-representative-sample-of-adult-twitter-users-in-the-u-s-f4da353f538a">this companion post</a>. The 2021 sample also remained large enough to analyze major subgroups of adult Twitter users in the U.S., such as men and women or Democrats and Republicans.</p><p>There are also benefits to using our new consent language that go beyond raw numbers. Most importantly, we can feel confident that our panelists have access to better information about what we are planning to do with their Twitter data and how long we will use their personal information. For this reason alone, we can consider this adjustment a success, even if we didn’t reach our loftiest ambitions in terms of convincing more respondents to provide us with their handles.</p><p><em>This post was written by Athena Chapekis and Emma Remy, who are data science analysts at Pew Research Center.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bf5b36d1bdd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pew-research-center-decoded/evaluating-changes-in-how-we-ask-americans-for-their-twitter-profiles-8bf5b36d1bdd">Evaluating changes in how we ask Americans for their Twitter profiles</a> was originally published in <a href="https://medium.com/pew-research-center-decoded">Pew Research Center: Decoded</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>