logo
down
shadow

Barchart grouped by variable both count up to 100 percent


Barchart grouped by variable both count up to 100 percent

By : user7455091
Date : November 21 2020, 03:00 PM
Any of those help You just need to add a group to before you do your prop.table() calculation.
The only change is the group_by(Phase) line.
code :
require(dplyr)
require(ggplot2)

BEAdata %>% 
  count(Phase = factor(Phase), Activities = factor(Activities)) %>% 
  group_by(Phase) %>%
  mutate(pct = prop.table(n) * 100) %>% 
  ggplot(aes(x = Phase, y = n, fill = Activities)) + 
    geom_bar(stat = 'identity', position = 'dodge') + 
    geom_text(aes(y = n + .2,    # nudge above top of bar
              label = paste0(round(pct, 2), '%')),    # prettify
              position = position_dodge(width = .9), 
              size = 3)


Share : facebook icon twitter icon
ggvis side-by-side barchart grouped by second variable

ggvis side-by-side barchart grouped by second variable


By : user3190424
Date : March 29 2020, 07:55 AM
I wish this helpful for you I don't see an easy way to do this yet. But a work around is to explicitly define your x axis as a combination of your x and fill variables:
code :
library(ggivs)
library(dplyr)

steps <-c("A","B","C","D","A","B","C","D")
ratio <-c(1.1,1.5,1.7,1.4,1.5,1.7,1.4,1.9)
feature <-c("cc","cc","cc","cc","ca","ca","ca","ca")
shrink <- data.frame(steps,ratio,feature)


shrink %>% 
   mutate(steps_feature = factor(paste(steps, feature))) %>%
   ggvis(x= ~steps_feature, y= ~ratio, fill = ~feature) %>% 
   layer_bars(stack = FALSE) 
library(tidyr)
shrink %>%
   spread(feature, ratio) %>%
   ggvis(x = ~ca, y = ~cc, text := ~steps) %>%
   layer_text(fontSize := 35)
Grouped columns in barchart with variable count of data entries using ios-charts library

Grouped columns in barchart with variable count of data entries using ios-charts library


By : Frankie Jj
Date : March 29 2020, 07:55 AM
should help you out It is a bug, and, I think you have opened this issue on github, right? Anyway, you should be able to proceed with the fix: https://github.com/danielgindi/ios-charts/pull/248.
if there are two bars in one group, there should be only two dataSets, not 4, and each dataSet has two dataEntries. What you are using has 4 dataSets, and it leads to more space left for each x axis zone, that's why it is not centered.
Stacked ggplot percent barchart in shiny

Stacked ggplot percent barchart in shiny


By : Jonathan Lloyd
Date : March 29 2020, 07:55 AM
it should still fix some issue The error from your paste0 command comes because it is the last line in the reactive, and thus becomes the return value. Just add a statement return(df) or something equivalent and that will fix that problem.
As for the label positioning, the code is working as designed, you will have to calculate the desired positions for the geom_text and use those coordinates explicitly.That will require you summing up the coordinates for each individual brand segment so you know its left and right positions and can calculate the center.
How to center stacked percent barchart labels

How to center stacked percent barchart labels


By : ujjval
Date : March 29 2020, 07:55 AM
hope this fix your issue Here's how to center the labels and avoid plotting labels for small percentages. An additional issue in your data is that you have multiple bar sections for each colour. Instead, it seems to me all the bar sections of a given colour should be combined. The code below uses dplyr instead of plyr to set up the data for plotting:
code :
library(dplyr)

# Initial data frame   
df <- data.frame(Category, Brand, USD)

# Calculate percentages
df.summary = df %>% group_by(Brand, Category) %>% 
  summarise(USD = sum(USD)) %>%   # Within each Brand, sum all values in each Category
  mutate(percent = USD/sum(USD))
ggplot(df.summary, aes(x=reorder(Brand, USD, sum), y=percent, fill=Category)) +
  geom_bar(stat="identity", width = .7, colour="black", lwd=0.1) +
  geom_text(aes(label=ifelse(percent >= 0.07, paste0(sprintf("%.0f", percent*100),"%"),"")),
                position=position_stack(vjust=0.5), colour="white") +
  coord_flip() +
  scale_y_continuous(labels = percent_format()) +
  labs(y="", x="")
# Calculate percentages and label positions
df.summary = df %>% group_by(Brand, Category) %>% 
  summarise(USD = sum(USD)) %>%   # Within each Brand, sum all values in each Category
  mutate(percent = USD/sum(USD),
         pos = cumsum(percent) - 0.5*percent)
ggplot(df.summary, aes(x=reorder(Brand,USD,function(x)+sum(x)), y=percent, fill=Category)) +
  geom_bar(stat='identity',  width = .7, colour="black", lwd=0.1) +
  geom_text(aes(label=ifelse(percent >= 0.07, paste0(sprintf("%.0f", percent*100),"%"),""),
                y=pos), colour="white") +
  coord_flip() +
  scale_y_continuous(labels = percent_format()) +
  labs(y="", x="")
R - geom_bar Grouped Barchart with grouped Labels

R - geom_bar Grouped Barchart with grouped Labels


By : jiebai720
Date : March 29 2020, 07:55 AM
hope this fix your issue zoo::as.yearmon expects %b i.e. the abbreviated month name (e.g. Jan, Feb etc) in the locale of your system.
In this case you seem to be using month in German format but you locale is different. You can check your current setting using
code :
Sys.getlocale()
Sys.setlocale("LC_TIME", "de_DE")  #Mac
Sys.setlocale("LC_TIME", "German") #Windows
Related Posts Related Posts :
  • R 'cowplot' neatly produce gridded plot with shared (common) legends and unique legends
  • Repeat R script for many times and save results to text file
  • How to negative lookbehind for special characters
  • data.table inner join produces error when no match is found
  • Create a new column base on existing column, but row above
  • Is there a way to visualize the process of source() in RStudio?
  • google places api consumes 10 request but I am doing only 1
  • Statistical mode of a categorical variable in R (using mlv)
  • Using for-loop to mutate a data.frame in r
  • Make plot with regression line for mixed model
  • Shortcut to select matces cases in R studio
  • vectoriced norm/matrix multiplication
  • Negative log10 transformation in R
  • Plot data with duplicate points
  • Visualizing crosstab tables with a plot in R - changing colours
  • How to manually modify automated numbers and labels in plot
  • How can I follow any redirections of a url in R?
  • Add jitter to box plot using markers in plotly
  • Adding an extra item to the legend
  • ggplot fills in data in the wrong order
  • Convert list to data frame
  • R: filtering by list(s) of strings and returning all results that start with the content of the lists
  • R:How to attach parts of a data frame with different headers and/or an overflowing piece of the dat frame
  • How to use 'par' for manipulating plot margins?
  • Can dplyr::case_when return mix of NAs and non-NAs?
  • Text preprocessing and topic modelling using text2vec package
  • Uploading multiple files in Shiny, process the files, rbind the results and return a download
  • R levelplot: color green-white-red (white on 0) according to one variable, but show the values of another variable
  • Why [i] doesn't point to the starting point in a vector
  • In R after generating a mvrnorm distribution, Y, what does Y[,1] do?
  • expand a data frame to have as many rows as range of two columns in original row
  • Getting started with R and CFA
  • Re order x-axis in ggplot so time goes from 12AM to 11PM in R
  • R - Automatically stack every nth column of a data frame and save them as new objects
  • How to format dplyr output in R into doubles (or other workable format)?
  • Dataframe to matrix conversion using tapply turns zeros to NAs
  • Smallest multiple of 1:20 - How can I make it quicker?
  • How to specify the size of a graph in ggplot2 independent of axis labels
  • How can I find the number of a vector's elements in another vector?
  • ROC curve from train/test set in caret R package
  • Random Forest for a mixture of categorical,numeric and "unwanted" variables which include missing values
  • extract certain data from multiple excel files with R
  • Matrix with counts of wins and losses between methods in R
  • Grouping string variables from a dataframe by best string match to make subsets
  • Reorder does not work after adding second geom_points
  • cover POS data formate to the one can apply Arules (Apriori)
  • Matching values between data frames based on overlapping dates
  • Grouped bar chart turns into stacked bar chart ggplot
  • R: How to fill in NA Values within a Column based on grouping?
  • Two action buttons, but only the first one, that is written in the server file, works?
  • Converting time in R to 24 hours
  • R - Web scrapping and downloading multiple zip files and save the files without overwriting
  • Find month and year inside string
  • Append multiple csv files into one file using R
  • Use `purrr::map` with k-means
  • R - 'data' is not an exported object from 'namespace:my_package'
  • Sum vector with number by dinamic intervals without looping
  • Issues with ave function in R: error "cannot allocate vector of size 419 kb."
  • Shiny system call with continuous updates
  • Unable to un-nest some fields using google bigquery (standard)
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org