aesthetics

Add legend to ggplot histogram with different types of aesthetics

不打扰是莪最后的温柔 提交于 2020-02-02 08:23:08
问题 I want to add a legend to one of my plots, but I have different aesthetics and I never created a legend so I find it very difficult to determine how to build it. One of my aesthetics is a fill code, which I added manually as a vector. The other aesthetic is a vertical line that I added with geom_vline. From the graph below, there are three characteristics that I want to add to the legend: 1) The bars with color dark blue, 2) The bars with color light blue and 3) The vertical line. Does anyone

Add legend to ggplot histogram with different types of aesthetics

主宰稳场 提交于 2020-02-02 08:22:06
问题 I want to add a legend to one of my plots, but I have different aesthetics and I never created a legend so I find it very difficult to determine how to build it. One of my aesthetics is a fill code, which I added manually as a vector. The other aesthetic is a vertical line that I added with geom_vline. From the graph below, there are three characteristics that I want to add to the legend: 1) The bars with color dark blue, 2) The bars with color light blue and 3) The vertical line. Does anyone

How to manually set colours *conditionally* in aes() AND local geom_xxx() in ggplot?

我的梦境 提交于 2020-01-25 07:52:45
问题 I'm trying to make a function that can take either a single group, or several groups, while using a single colour argument. However, there seems to be a problem in specifying colour both globally (in aes() ) and locally (in geom_smooth() ). Looks like aes() doesn't accept colour=NULL or just left empty colour= . Plot without groups (works) scatterfunction <- function (Data=mtcars,Predictor=mtcars$wt,Response=mtcars$mpg,what.Colour="purple") { library(ggplot2) ggplot(Data,aes(x=Predictor,y

How to add black border to matplotlib 2.0 `ax` object In Python 3?

北城以北 提交于 2020-01-02 04:34:21
问题 I've been using style sheets in matplotlib lately. I really like how clean the seaborn-white looks and I want to be able to add the border to other styles like ggplot or seaborn-whitegrid . How can I add a black border around my ax object from fig, ax = plt.subplots() ? import pandas as pd import numpy as np from collections import * Se_data = pd.Series(Counter(np.random.randint(0,10,100))) with plt.style.context("seaborn-whitegrid"): fig, ax = plt.subplots() Se_data.plot(kind="barh", ax=ax,

Dash in column name yields “object not found” Error

天大地大妈咪最大 提交于 2019-12-31 04:27:06
问题 I have a function to generate scatter plots from data, where an argument is provided to select which column to use for coloring the points. Here is a simplified version: library(ggplot2) plot_gene <- function (df, gene) { ggplot(df, aes(x, y)) + geom_point(aes_string(col = gene)) + scale_color_gradient() } where df is a data.frame with columns x , y , and then a bunch of gene names. This works fine for most gene names; however, some have dashes and these fail: print(plot_gene(df, "Gapdh")) #

changing line width in stat_qq (with ggplot, in r)

◇◆丶佛笑我妖孽 提交于 2019-12-25 02:38:30
问题 I am using ggplot with stat_qq to plot several samples. I am trying to figure out how to change the width of the lines in the chart with no luck :-( Here is (the relevant part of) my code: ggplot(data=df,aes(sample=obser, colour = sample)) + stat_qq(dist=qunif) + scale_color_manual(values = c("samp_a" = "darkturquoise", "samp_b" = "hotpink", "samp_c" = "darkgrey")) + scale_x_continuous(breaks=x_ax) + scale_y_continuous(breaks=y_ax) + theme(axis.text.x = element_text(angle = 90, hjust = 1,size

How to properly use variable in ggplot?

被刻印的时光 ゝ 提交于 2019-12-24 21:31:08
问题 I have found an issue, that I was unable to understand. Can someone please point to an explanation? In ggplot, if I use/don't use "$" with variable name , it gives different result. Please see the example below, library(ggplot2) df <- read.csv("pseudo_facebook.tsv", sep = '\t') # Without $ sign ggplot(data = df, aes(x = friend_count)) + geom_histogram(binwidth = 25) + scale_x_continuous(limits = c(1, 1000), breaks = seq(0, 1000, 25)) + facet_grid(~df$gender) # With $ sign ggplot(data = df,

ggplot: Error: Aesthetics must be either length 1 or the same as the data (10): x, y, group

泪湿孤枕 提交于 2019-12-24 18:23:17
问题 I have a small dataset and I want to plot it with a line graph: > Gain quantile Positives Total_Examples Positive_Prevalence Lift Cumsum_Positives 1: (0, ] 1 1 1 1.428571 0.1428571 2: (1.9,2.8] 1 1 1 1.428571 0.2857143 3: (2.8,3.7] 1 1 1 1.428571 0.4285714 4: (3.7,4.6] 1 1 1 1.428571 0.5714286 5: (4.6,5.5] 1 1 1 1.428571 0.7142857 6: (5.5,6.4] 1 1 1 1.428571 0.8571429 7: (6.4,7.3] 1 1 1 1.428571 1.0000000 8: (7.3,8.2] 0 1 0 0.000000 1.0000000 9: (8.2,9.1] 0 1 0 0.000000 1.0000000 10: (9.1,10]

Passing data and column names to ggplot via another function

末鹿安然 提交于 2019-12-23 22:08:27
问题 I'll skip right to an example and comment afterwords: cont <- data.frame(value = c(1:20),variable = c(1:20,(1:20)^1.5,(1:20)^2),group=rep(c(1,2,3),each=20)) value variable group 1 1 1.000000 1 2 2 2.000000 1 3 3 3.000000 1 #... etc. #ser is shorthand for "series". plot_scat <- function(data,x,y,ser) { ggplot(data,aes(x=x,y=y,color=factor(ser)))+geom_point() } plot_scat(cont,value,variable,group) #This gives the error: #Error in eval(expr,envir,enclose) : object 'x' not found Now, I know that