torte: Tortendiagramm

View source: R/9-piechart-torte.R

torteR Documentation

Tortendiagramm

Description

Quelle: https://r.789695.n4.nabble.com/Multi-panel-Pie-Charts-td1687026.html

Das ist eine Kopie aus lattice Seite 253

Usage

torte(x, data, drop.unused.levels = FALSE, ...)

panel.piechart(
  x,
  y,
  groups,
  labels = levels(groups),
  percent = TRUE,
  edges = 200,
  radius = 0.8,
  clockwise = FALSE,
  init.angle = if (clockwise) 90 else 0,
  density = NULL,
  angle = 45,
  col = superpose.polygon$col,
  border = superpose.polygon$border,
  mar = c(2, 2, 2, 2) - 0.2,
  digits = 0,
  lty = superpose.polygon$lty,
  ...
)

piechart(x, data = NULL, panel = "panel.piechart", xlab = "", ...)

gtorte(
  x,
  data,
  main = "",
  col = NULL,
  cex.key = 1,
  margin = 2,
  cex.ltext = 1.1,
  wrap = NULL,
  cbPalette = c(orange = "#E69F00", skyblue = "#56B4E9", green = "#009E73", yellow =
    "#F0E442", blue = "#0072B2", vermillion = "#D55E00", purple = "#CC79A7"),
  ...
)

Arguments

x

Formula

data

daten

drop.unused.levels

an xtab

...
labels

ist entweder die levels von groups oder ein character string

percent

digits Anzeigen der Prozent

edges, radius, clockwise, init.angle, density, angle, col, border, mar, lty

an graphics::pie

col

Farbe

cex.key

Schriftgrösse

margin

an to_table

wrap

Titel wrap_string -> main

x, y, groups

kommt vom panel

Value

lattice

ggplot

Examples

require(stp25plot)
require(lattice)
set.seed(2)
n<-20*3*2

DF <- data.frame(
  n = runif(n, min = 1, max = 5),
  e = runif(n, min = 1, max = 5),
  o = runif(n, min = 1, max = 5),
  g = runif(n, min = 1, max = 5),
  a = runif(n, min = 1, max = 5),
  treatment = gl(3, n / 3, labels = c("UG1", "UG2", "KG"))[sample.int(n)],
  sex = gl(2, n / 2, labels = c("male", "female"))
) |>
  stp25tools::Label(
    n = "Neurotizismus",
    e = "Extraversion",
    o = "Offenheit fuer Erfahrungen",
    g = "Gewissenhaftigkeit",
    a = "Vertraeglichkeit"
  )

DF[1, 1:3] <- 5
DF[1, 4:5] <- 1
DF[2:10, 1] <- 4.5
DF[n, 4:5] <- 5
DF[n, 1:5] <- 1

torte( ~ treatment, DF, init.angle = 45, main = "lattice")
torte( ~ treatment + sex, DF, init.angle = 45, main = "lattice")



require(ggplot2)
# Create test data.
data <- data.frame(
  category=c("Granulocytes", "CD3+", "CD56+",  "CD19+", "Monocytes"),
  count=c(80,10,5,3,2)
)

# Compute percentages
data$fraction <- data$count / sum(data$count)
# Compute the cumulative percentages (top of each rectangle)
data$ymax <- cumsum(data$fraction)
# Compute the bottom of each rectangle
data$ymin <- c(0, head(data$ymax, n=-1))
# Compute label position
data$labelPosition <- (data$ymax + data$ymin) / 2
# Compute a good label
#data$label <- paste0(data$category, "\n value: ", data$count)
data
# Make the plot
P1<- data |> ggplot(
  aes(ymax=ymax, ymin=ymin, xmax=4, xmin=2,
      fill=category)) +
  geom_rect() +
  # geom_text( x=2,
  #            aes(y=labelPosition,
  #                label=label,
  #                color=1), size=6) + # x here controls label position (inner / outer)
  scale_fill_manual(
    values =
      c("#918E00","#00F801","#FF2600","#0433FF","#FE9300")) +
  coord_polar(theta="y") +
  xlim(c(-1, 4)) +
  theme_void() +
  theme(legend.position = "top") +
  labs(title = "Leukocyte composition 1h NMP") +
  theme(legend.title = element_blank(),# element_text(size=12, color = "salmon", face="bold"),
        legend.justification=c(0,1),
        legend.position=c(0.4, 0.7),
        legend.background = element_blank(),
        legend.key = element_blank()
  )
P1

ggplot(data, aes(x = 1, y = count , fill = category )) +
  # Make pie
  coord_polar(theta = "y") +
  # Add the *stacked* columns
  geom_col(position = position_stack(reverse = TRUE),
           color = "tan3", 
           size = 3, show.legend = FALSE) +
  # Add labels to the *stacked* position,
  # in the middle of the column (vjust = 0.5)
  geom_text(aes(label = category),
            position = position_stack(vjust = 0.5, reverse = TRUE)) +
  theme_void() +
  labs(title = "Relative time spent building piecharts with ggplot2")

tab <- as.data.frame(xtabs( ~ treatment + sex, DF))

# geht nur mit 
plot.new()
barchart(
  ~ Freq | sex,
  tab,
  groups = treatment, scales=list(draw = FALSE), xlab="",
  auto.key = list(columns = 3), 
  par.settings = bw_theme(farbe()),
  layout= c(2,1),
  panel = panel.piechart
)


tab <- as.data.frame(xtabs( ~ treatment + sex, DF))

barchart(
  ~ Freq | sex,
  tab,
  groups = treatment, scales=list(draw = FALSE), xlab="",
  auto.key = list(columns = 3),
  panel = panel.piechart
)


piechart(~Freq|sex, tab, groups= treatment, auto.key=list(columns=3))
tab <- as.data.frame(xtabs( ~ treatment + sex, DF))



piechart(~Freq|sex, tab, groups= treatment, auto.key=list(columns=3))


 gtorte(~treatment+sex, DF, init.angle=45, main="ggplot")



stp4/stp25plot documentation built on March 29, 2025, 4:26 p.m.