plot

Coloring the points by category in R

青春壹個敷衍的年華 提交于 2021-02-11 14:05:35
问题 I am creating a scatter plot in R using the following code: plot(df_prob1$x1, df_prob1$x2, pch = df_prob1$y) I get the following plot: As seen in the above plot there are two categories, one represented by a square and the other by circle. I want these two categories to have different colors as well. I did try using the following code: plot(df_prob1$x1, df_prob1$x2, pch = df_prob1$y, col = c("red", "blue")) And I get the following plot: However, it is randomly coloring points and not taking

How to make a plot in r with multiple lines using ggplot

早过忘川 提交于 2021-02-11 13:59:54
问题 I am trying to do a graph in r with 3 lines using ggplot, but the third line does not appear in the graph. I used the following code: us_idlpnts <- subset(unvoting, CountryName == "United States of America") rus_idlpnts <- subset(unvoting, CountryName == "Russia") mdn_idl_pnt <- summarize(unvoting, PctAgreeUS = median(PctAgreeUS, na.rm=T), PctAgreeRUSSIA = median(PctAgreeRUSSIA, na.rm=T), idealpoint = median(idealpoint, na.rm=T), Year = median(Year, na.rm= T)) ggplot(NULL, aes(Year,

How to make a plot in r with multiple lines using ggplot

流过昼夜 提交于 2021-02-11 13:58:53
问题 I am trying to do a graph in r with 3 lines using ggplot, but the third line does not appear in the graph. I used the following code: us_idlpnts <- subset(unvoting, CountryName == "United States of America") rus_idlpnts <- subset(unvoting, CountryName == "Russia") mdn_idl_pnt <- summarize(unvoting, PctAgreeUS = median(PctAgreeUS, na.rm=T), PctAgreeRUSSIA = median(PctAgreeRUSSIA, na.rm=T), idealpoint = median(idealpoint, na.rm=T), Year = median(Year, na.rm= T)) ggplot(NULL, aes(Year,

R: Overlay Poisson distribution over histogram of data

与世无争的帅哥 提交于 2021-02-11 13:44:15
问题 I have some discrete data, which I have plotted in a histogram. I'd like to overlay a Poisson distribution to show the data is roughly Poisson distributed. Imagine the two plots from the code below merging into one plot, that is what I'd like to achieve. # Read data data <- read.csv("data.csv") # Plot data hist(data, prob=TRUE) # Plot Poisson c <- c(0:7) plot(c, dpois(c, mean(data)), type="l") I have tried the curve function: curve(c, dpois(x=c, lambda=mean(data)), add=T) But all I get is

I'm reading images on the disk, how to plot like the first 50 images?

给你一囗甜甜゛ 提交于 2021-02-11 13:13:03
问题 I am reading images on the disk, how to make a for and where to put it to plot the first 50 images on the screen, I want to make sure, that I'm reading the right images, it's for deep learning. def load_clef_database(): img_data_list = [] dataset_dir = "/Users/PlantCLEF2015" root = os.path.join(dataset_dir, 'train') filenames = [] # files class_species = [] class_species_unique = [] class_species_unique_id = [] class_familys = [] class_geni = [] class_ids = [] class_contents = [] metadata = [

I'm reading images on the disk, how to plot like the first 50 images?

穿精又带淫゛_ 提交于 2021-02-11 13:11:08
问题 I am reading images on the disk, how to make a for and where to put it to plot the first 50 images on the screen, I want to make sure, that I'm reading the right images, it's for deep learning. def load_clef_database(): img_data_list = [] dataset_dir = "/Users/PlantCLEF2015" root = os.path.join(dataset_dir, 'train') filenames = [] # files class_species = [] class_species_unique = [] class_species_unique_id = [] class_familys = [] class_geni = [] class_ids = [] class_contents = [] metadata = [

Letter frequencies: plot a histogram ordering the values PYTHON

百般思念 提交于 2021-02-11 12:56:58
问题 What I am trying to do is to analyse the frequency of the letters in a text. As an example, I will use here a small sentence, but all that is thought to analyse huge texts (so it's better to be efficient). Well, I have the following text: test = "quatre jutges dun jutjat mengen fetge dun penjat" Then I created a function which counts the frequencies def create_dictionary2(txt): dictionary = {} i=0 for x in set(txt): dictionary[x] = txt.count(x)/len(txt) return dictionary And then import numpy

Plotly Annotation covered by the Node and Background [closed]

无人久伴 提交于 2021-02-11 12:48:57
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 days ago . Improve this question I've followed the example on plotting the tree from https://plotly.com/python/tree-plots/. However, I've a very long annotation but it is covered by the background such that it is cut off. Is it possible to annotate it outside the circle? I've pasted the code below. It can be run

Matplotlib Line vs. Bar plot DateTime axis formatting

ⅰ亾dé卋堺 提交于 2021-02-11 12:29:30
问题 I have a DataFrame with a DateTime index: import pandas as pd from random import randrange dates = pd.date_range(start="2020-02-01",end='2020-04-18',freq='1d') df = pd.DataFrame(index=dates,data=[randrange(10000) for i in range(78)] Now when I plot the data as a line plot, matplotlib produces a nicely formatted x axis: df.plot(figsize=(12,4)) However, if instead I do a bar plot, I now get something quite horrible: df.plot(kind='bar',figsize=(12,4)), This is quite disconcerting, as it is the

R: Using aggregate within a function, not working

你。 提交于 2021-02-11 12:28:17
问题 I am fairly new to R so apologies if an answer to this already exists that I am unable to find. I cannot replicate the exact error I have with my own dataset, but since an error is produced nonetheless here we go. What I am trying to do is to create a function to calculate the average of several columns conditionnal on the values of other ones. Let's say that d1 <- c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4) d2 <- c(1:12) d3 <- c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2) df <- cbind(d1, d2, d3)