JH P
JH P

Reputation: 21

Groups with fewer than two data points have been dropped. ggplot r

A couple of weeks ago, I drew a ggplot density plot in r. It worked fine. And then yesterday, I revisited and ran the same code. There was absolutely no change in the body of the code (only change in the Rmarkdown formatting like changing font size of texts, echo = FALSE, etc). I simply re-ran the same code and for some reason it does not work.

Here's the code for the dataset:

m_hospitals = m_hospitals %>% group_by(Provider.Name) %>% summarise(accSum = 
sum(Average.Covered.Charges), atpSum = sum(Average.Total.Payments), ampSum = 
sum(Average.Medicare.Payments), accMean = mean(Average.Covered.Charges), 
atpMean = mean(Average.Total.Payments), ampMean = 
mean(Average.Medicare.Payments)) 

#Take a sample
set.seed(1219)
sample_m_hospitals = m_hospitals[sample(nrow(m_hospitals), 30), ]

And here's the code for the plot that worked before but not anymore:

ggplot(data = sample_m_hospitals) +
aes(x = Provider.Name, y = accMean) + 
geom_density(alpha = .75) + theme(axis.text.x = element_text(angle = 45, 
hjust = 1))

It's giving me this message, "Groups with fewer than two data points have been dropped" * 30. It is true that each of 30 rows only has 1 observation because they are summarised. Funny thing is, the message did not pop up before, did not drop any data points and worked fine. I even have the screenshot I took for the plot drawn. Here's the link: 1

One change I feel suspicious about is updating R (updated before re-plotting, 3.5.0 > 3.5.1) which erased all my libraries that I had to re-install all of them. But I'm not sure if the update has to do anything with this issue. It worked fine, but why is it suddenly not working? I don't understand.. Please help! I just wanna plot this in similar form however possible.

Contents updated as per you guys' comments:

Screenshots for devtools::session_info() 2 , 3

Screenshots for sample_m_hospitals 4 , 5

Upvotes: 2

Views: 5758

Answers (1)

Sherman
Sherman

Reputation: 555

I had a similar issue which was resolved by converting columns. Numeric columns were being imported as strings.

Upvotes: 1

Related Questions