How to solve this problem?

When knit to HTML my chart is missing some value? How to solve kind of this issue?

library(tidyverse)
library(patchwork)
library(dplyr)
set.seed(11)
diamonds <- diamonds %>%
  sample_n(5393)

diamonds <- diamonds %>%
  mutate(cut_short = case_when(cut == "Fair" ~ "F",
                               cut == "Good" ~ "G",
                               cut == "Very Good" ~ "VG",
                               cut == "Premium" ~ "P",
                               cut == "Ideal" ~ "I",
                               TRUE ~ NA_character_))

diamonds$shape <- ifelse(diamonds$x == diamonds$y & diamonds$x == diamonds$z, "Round",
                         ifelse(diamonds$x == diamonds$y & diamonds$x != diamonds$z, "Square",
                                ifelse(diamonds$x != diamonds$y, "Non-round", NA)))

ggplot(diamonds, aes(x = cut_short, y = price, fill = cut)) +
  geom_boxplot() +
  facet_wrap(~ shape) +
  theme_minimal() +
  labs(x = "Diamonds Cut", y = "Price", fill = "Diamonds Cut")


1 Like

HI @Sarach_Sriklab ,

Add na.rm = TRUE in geom_boxplot() attributes.

ggplot(diamonds, aes(x = cut_short, y = price, fill = cut)) +
  geom_boxplot(na.rm = TRUE) +
  facet_wrap(~ shape) +
  theme_minimal() +
  labs(x = "Diamonds Cut", y = "Price", fill = "Diamonds Cut")

Hi @M_AcostaCH
Thank you for your swift reply. However, I still get the same result when knit to HTML. Do I need to try PDF?

When I execute your code in R console I get the same chart as in your Rmd file. Do you still see a difference after starting fresh and reexecuting your chunk inline ?

I bet that the difference between the two charts ; is the initial sampling code; you probably didnt have it when you made the first image, but do have it when you are making the second image;

diamonds <- diamonds %>%
  sample_n(5393)

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.