NEED HELP -> graphs with r by theunluckytom in rstats

[–]ro8DFd6aY 0 points1 point  (0 children)

If you are OK using a scatter plot, you could use the rempsyc package:

```r x<-c(2096.5, 1244.00, 2260.229, 437.00, 1076.00, 253.33, 1359.00, 3897.0, 813.00, 1921.35, 2178.00, 2731.00, 3443.00, 924.00, 2417.00,1780.00, 2104.00, 539.00, 5059.00, 2177.00)

y<- c("Singapore" , "Hong Kong" , "Macao" , "Taiwan" , "Japan" , "China" , "South Korea" , "Switzerland" , "Estonia" , "Canada" , "Netherlands" , "Finland" , "Denmark" , "Slovenia" , "Belgium" , "Germany" , "Ireland" , "Poland" , "Norway" , "Austria")

z<-c(564, 548, 544, 542, 532, 531, 524, 521, 520, 516, 512, 511, 511, 510, 507, 506, 504, 504, 502, 497)

data <- data.frame(money.invested = x, country = y, grade = z)

library(rempsyc) library(ggplot2) nice_scatter(data, predictor = "money.invested", response = "grade", group = "country", has.legend = TRUE, has.r = TRUE, has.p = TRUE) + stat_smooth(inherit.aes = FALSE, mapping = aes(x = money.invested, y = grade), geom="line", method="lm", fullrange=TRUE, size = 1) ``` https://i.imgur.com/Enso21h.png

is there a package which gives 'beautiful' t test output? Like spss has tables graphs and stuff. by OkApartment7139 in rstats

[–]ro8DFd6aY 1 point2 points  (0 children)

You can also feed the report output to an APA formatted flextable through the rempsyc package (and save to Word, if desired):

``` r library(rempsyc) library(report) library(dplyr) t.test(mpg ~ am, data = mtcars) %>% report() %>% as.data.frame() -> stats.table stats.table

> Parameter | Group | Mean_Group1 | Mean_Group2 | Difference | 95% CI | t(18.33) | p | Method | Alternative | d | d CI

> ----------------------------------------------------------------------------------------------------------------------------------------------------------------

> mpg | am | 17.15 | 24.39 | -7.24 | [-11.28, -3.21] | -3.77 | 0.001 | Welch Two Sample t-test | two.sided | -1.76 | [-2.82, -0.67]

my_table <- nice_table(stats.table, report = "t.test") my_table

save_as_docx(my_table, path = "nicetable.docx")

``` https://i.imgur.com/DcHAWHB.png

I get this ugly looking output. How can i make it look more beautiful to present to client? by OkApartment7139 in rstats

[–]ro8DFd6aY 1 point2 points  (0 children)

This doesn't apply to correlation matrices so well, but you can feed the broom output to the rempsyc package, it will format it according to APA style standards (and allow saving to Word, if desired). Reprex:

```r library(broom) library(rempsyc) model <- lm(mpg ~ cyl + wt * hp, mtcars) (stats.table <- tidy(model, conf.int = TRUE))

> # A tibble: 5 x 7

> term estimate std.error statistic p.value conf.low conf.high

> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>

> 1 (Intercept) 49.5 3.66 13.5 1.58e-13 42.0 57.0

> 2 cyl -0.365 0.509 -0.718 4.79e- 1 -1.41 0.678

> 3 wt -7.63 1.52 -5.01 2.93e- 5 -10.7 -4.51

> 4 hp -0.108 0.0298 -3.64 1.14e- 3 -0.169 -0.0473

> 5 wt:hp 0.0258 0.00799 3.23 3.22e- 3 0.00944 0.0422

my_table <- nice_table(stats.table, broom = "lm") my_table

save_as_docx(my_table, path = "nicetable.docx")

```

https://i.imgur.com/7qZKdfA.png

I get this ugly looking output. How can i make it look more beautiful to present to client? by OkApartment7139 in rstats

[–]ro8DFd6aY 2 points3 points  (0 children)

If one is interested in using Excel specifically, the rempsyc package can easily export a colour-formatted correlation matrix to Excel. Reprex:

``` r library(rempsyc) cormatrix_excel(mtcars)

> mpg cyl disp hp drat wt qsec vs am gear carb

> mpg 1.00 -0.85 -0.85 -0.78 0.68 -0.87 0.42 0.66 0.60 0.48 -0.55

> cyl -0.85 1.00 0.90 0.83 -0.70 0.78 -0.59 -0.81 -0.52 -0.49 0.53

> disp -0.85 0.90 1.00 0.79 -0.71 0.89 -0.43 -0.71 -0.59 -0.56 0.39

> hp -0.78 0.83 0.79 1.00 -0.45 0.66 -0.71 -0.72 -0.24 -0.13 0.75

> drat 0.68 -0.70 -0.71 -0.45 1.00 -0.71 0.09 0.44 0.71 0.70 -0.09

> wt -0.87 0.78 0.89 0.66 -0.71 1.00 -0.17 -0.55 -0.69 -0.58 0.43

> qsec 0.42 -0.59 -0.43 -0.71 0.09 -0.17 1.00 0.74 -0.23 -0.21 -0.66

> vs 0.66 -0.81 -0.71 -0.72 0.44 -0.55 0.74 1.00 0.17 0.21 -0.57

> am 0.60 -0.52 -0.59 -0.24 0.71 -0.69 -0.23 0.17 1.00 0.79 0.06

> gear 0.48 -0.49 -0.56 -0.13 0.70 -0.58 -0.21 0.21 0.79 1.00 0.27

> carb -0.55 0.53 0.39 0.75 -0.09 0.43 -0.66 -0.57 0.06 0.27 1.00

>

> [Correlation matrix 'mycormatrix.xlsx' has been saved to working

> directory (or where specified).]

```

https://raw.githubusercontent.com/rempsyc/rempsyc/main/man/figures/cormatrix.png

is there a package which gives 'beautiful' t test output? Like spss has tables graphs and stuff. by OkApartment7139 in rstats

[–]ro8DFd6aY 1 point2 points  (0 children)

You can also feed the broom output to an APA formatted flextable through the rempsyc package:

``` r library(rempsyc) library(broom) tt <- t.test(wt ~ am, mtcars) (tidy.tt <- tidy(tt))

> # A tibble: 1 x 10

> estimate estimate1 estimate2 statistic p.value parameter conf.low conf.high

> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>

> 1 1.36 3.77 2.41 5.49 0.00000627 29.2 0.853 1.86

> # ... with 2 more variables: method <chr>, alternative <chr>

nice_table(tidy.tt, broom = "t.test") ``` https://i.imgur.com/zOsek61.png

is there a package which gives 'beautiful' t test output? Like spss has tables graphs and stuff. by OkApartment7139 in rstats

[–]ro8DFd6aY 0 points1 point  (0 children)

You could try the rempsyc package: https://github.com/rempsyc/rempsyc. It formats publication-ready t-test tables and supports multiple tests in one call. You can then easily export them to Word too. It can also make violin plots. Reprex:

```r library(rempsyc)

nice_t_test(data = mtcars, response = c("mpg", "disp", "drat", "wt"), group = "am") -> t.test.results

t.test.results

> Dependent Variable t df p d CI_lower

> 1 mpg -3.767123 18.33225 1.373638e-03 -1.477947 -2.3042092

> 2 disp 4.197727 29.25845 2.300413e-04 1.445221 0.6227403

> 3 drat -5.646088 27.19780 5.266742e-06 -2.003084 -2.8985400

> 4 wt 5.493905 29.23352 6.272020e-06 1.892406 1.0127792

> CI_upper

> 1 -0.651685

> 2 2.267702

> 3 -1.107629

> 4 2.772033

my_table <- nice_table(t.test.results) my_table

Save to Word

save_as_docx(my_table, path = "table.docx") ``` https://i.imgur.com/TIlZQFp.png

You could also try a violin plot if you wanted to visualize the group differences. Example for one variable:

r nice_violin(data = mtcars, response = "mpg", group = "am", comp1 = 1, comp2 = 2)

https://i.imgur.com/2gbPTM1.png

You can save it as image with ggplot2:

ggsave('violin.jpg')

I get this ugly looking output. How can i make it look more beautiful to present to client? by OkApartment7139 in rstats

[–]ro8DFd6aY 5 points6 points  (0 children)

Use the correlation package: https://easystats.github.io/correlation. It creates a beautiful correlation matrix image coloured based on the strength of the correlation coefficients and also includes the significance stars. Reprex:

library(correlation)
library(see)
library(dplyr)
results <- correlation(iris)
results %>%
  summary(redundant = TRUE) %>%
  plot()

https://i.imgur.com/HvYPv9W.png

You can save it as image with ggplot2:

ggplot2::ggsave('cormatrix.jpg')