我试图在几个月内为三种鲸鱼创建条形图。我的问题是,条的大小在几个月之间变化,因为有几个月没有看到任何一种。知道我该如何解决吗?
我使用以下代码:
land_based_individuals <- read.csv("Land_based_sightings_antero.csv",
header = T, sep =",", dec =",", stringsAsFactors = F)
land_based_individuals_month <- aggregate(land_based_individuals$sightings,
by = list(land_based_individuals$Month, land_based_individuals$Species),
FUN=sum)
colnames(land_based_sightings_month)[1] <- "Month"
colnames(land_based_sightings_month)[2] <- "Species"
colnames(land_based_sightings_month)[3] <- "Sightings"
library (ggplot2)
ggplot(land_based_sightings_month,
aes(fill=Species, y=Sightings, x=land_based_sightings_month$Month)) +
geom_bar(position="dodge", stat="identity") +
ggtitle("Land-based Sightings per month")+ xlab("Month")+ ylab("Sightings")+
scale_x_continuous("Month", labels = as.character(land_based_sightings_month$Month),
breaks = land_based_sightings_month$Month)+
ggsave(file="Land-based Sightings per month.png",
width = 14, height = 9, dpi = 120)
这是我从此data那里获得的信息图
答案 0 :(得分:2)
您可以使用import numpy as np
import cv2
# cv2.getGaborKernel(ksize, sigma, theta, lambda, gamma, psi, ktype)
# ksize - size of gabor filter (n, n)
# sigma - standard deviation of the gaussian function
# theta - orientation of the normal to the parallel stripes
# lambda - wavelength of the sunusoidal factor
# gamma - spatial aspect ratio
# psi - phase offset
# ktype - type and range of values that each pixel in the gabor kernel can hold
g_kernel = cv2.getGaborKernel((21, 21), 8.0, np.pi/4, 10.0, 0.5, 0, ktype=cv2.CV_32F)
img = cv2.imread('test.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
filtered_img = cv2.filter2D(img, cv2.CV_8UC3, g_kernel)
cv2.imshow('image', img)
cv2.imshow('filtered image', filtered_img)
h, w = g_kernel.shape[:2]
g_kernel = cv2.resize(g_kernel, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)
cv2.imshow('gabor kernel (resized)', g_kernel)
cv2.waitKey(0)
cv2.destroyAllWindows()
用0来填写缺失的tidyr::complete
-Month
组合。
Species
我还清理了您的代码,其中包含一些(次要)代码和格式问题。最重要的是,切勿在{{1}}的{{1}}内部使用library(tidyverse)
land_based_individuals %>%
group_by(Month, Species) %>%
summarise(Sightings = sum(Sightings)) %>%
complete(Month, Species, fill = list(Sightings = 0)) %>%
ggplot(aes(Month, Sightings, fill = Species)) +
geom_col(position = "dodge2") +
ggtitle("Land-based Sightings per month") +
xlab("Month") +
ylab("Sightings")
-index;使用时可能会导致令人讨厌和意外的结果方面。